From 9e8b86bb9ef84d6214a9ea2110cf6ed83f4ddcd3 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 1 Jan 2018 11:49:05 +0200 Subject: Fix race in scheduler progress setting logic --- build2/scheduler.hxx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'build2/scheduler.hxx') diff --git a/build2/scheduler.hxx b/build2/scheduler.hxx index f79ca3e..20e5128 100644 --- a/build2/scheduler.hxx +++ b/build2/scheduler.hxx @@ -160,6 +160,7 @@ namespace build2 // If the maximum threads or task queue depth arguments are unspecified, // then appropriate defaults are used. // + explicit scheduler (size_t max_active, size_t init_active = 1, size_t max_threads = 0, @@ -197,7 +198,7 @@ namespace build2 void tune (size_t max_active); - // Return true if the scheduler is running serial. + // Return true if the scheduler is configured to run tasks serially. // // Note: can only be called from threads that have observed startup. // @@ -255,6 +256,7 @@ namespace build2 { if (s_ != nullptr) { + s_->wait_idle (); // See monitor() for details. s_->monitor_count_ = nullptr; s_->monitor_func_ = nullptr; } @@ -298,6 +300,12 @@ namespace build2 task_queue_ = nullptr; } + // Assuming all the task have been executed, busy-wait for all the threads + // to become idle. Normally you don't need to call this function directly. + // + void + wait_idle (); + // Return the number of hardware threads or 0 if unable to determine. // static size_t -- cgit v1.1