From a71a4b5015327b15fb0bb4fea16c43f21ef0616c Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Fri, 22 Oct 2021 15:50:47 +0200 Subject: TaskSystem: Fix early shutdown ... conceptually, it was possible that a previous task decrements the `num_threads_running_` counter before it is incremented by the next task. Therefore, we have to unify the queue and thread status in a single counter (`total_workload_`) and ensure that woken threads increment it before decrementing it for popping a queue. --- test/buildtool/multithreading/task_system.test.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'test/buildtool/multithreading/task_system.test.cpp') diff --git a/test/buildtool/multithreading/task_system.test.cpp b/test/buildtool/multithreading/task_system.test.cpp index 21e1ca6e..d34e3e4b 100644 --- a/test/buildtool/multithreading/task_system.test.cpp +++ b/test/buildtool/multithreading/task_system.test.cpp @@ -174,14 +174,11 @@ TEST_CASE("All threads run until work is done", "[task_system]") { // Wait some time for all threads to go to sleep. std::this_thread::sleep_for(1s); - // Run singe task that creates the actual store tasks. All threads - // should stay alive until their corresponding queue is filled. - ts.QueueTask([&ts, &store_id] { - // One task per thread (assumes round-robin push to queues). - for (std::size_t i{}; i < ts.NumberOfThreads(); ++i) { - ts.QueueTask([&store_id] { store_id(); }); - } - }); + // All threads should stay alive until their corresponding queue is + // filled. One task per thread (assumes round-robin push to queues). + for (std::size_t i{}; i < ts.NumberOfThreads(); ++i) { + ts.QueueTask([&store_id] { store_id(); }); + } } CHECK(tids.size() == kNumThreads); } -- cgit v1.2.3