From 7aca10fd0bb203a62c3cf5fd53c9aa79ab10c9b1 Mon Sep 17 00:00:00 2001 From: David Wells Date: Sun, 28 May 2017 17:46:24 -0400 Subject: [PATCH] Clean up task_09 a bit. This commit applies some small cleanups to this test (e.g., preferring C++11 functionality to POSIX) and, in addition, makes the following changes: 1. The OK message won't be set to deallog until after tasks is destroyed (i.e., all threads must join). 2. If on a POSIX platform, unset the thread environment variable so that we really can run the 'right' number of threads. --- tests/base/task_09.cc | 60 ++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/tests/base/task_09.cc b/tests/base/task_09.cc index db2b79931a..fc02a2e4b6 100644 --- a/tests/base/task_09.cc +++ b/tests/base/task_09.cc @@ -22,9 +22,11 @@ // this test verifies that we no longer deadlock #include "../tests.h" -#include +#include #include -#include +#include + +#include #include #include @@ -32,27 +34,19 @@ void test () { - sleep (1); + std::this_thread::sleep_for(std::chrono::seconds(1)); } void outer () { - // wait for some time to make sure - // that really all outer tasks have - // been started, then start a bunch - // of new tasks and wait for them - // to finish. it used to be that - // the join() function used a mutex - // which could only be acquired - // once the spawned task has - // finished, but since we already - // have so many tasks running at - // this point, the children never - // get to run and so never release - // the mutex that we try to acquire - // in join() - sleep (1); + // wait for some time to make sure that really all outer tasks have been + // started, then start a bunch of new tasks and wait for them to finish. it + // used to be that the join() function used a mutex which could only be + // acquired once the spawned task has finished, but since we already have so + // many tasks running at this point, the children never get to run and so + // never release the mutex that we try to acquire in join() + std::this_thread::sleep_for(std::chrono::seconds(1)); Threads::new_task (test).join(); } @@ -65,17 +59,25 @@ int main() deallog.attach(logfile); deallog.threshold_double(1.e-10); - const std::size_t n_tasks = MultithreadInfo::n_cores()*2; - // Since this test relies on providing more tasks than there are cores, - // reset the concurrency limit that exists in tests.h: - MultithreadInfo::set_thread_limit(n_tasks); - std::vector> tasks(n_tasks); - for (std::size_t task_n=0; task_n> tasks(n_tasks); + for (std::size_t task_n=0; task_n