diff options
-rw-r--r-- | build2/algorithm.cxx | 2 | ||||
-rw-r--r-- | build2/scheduler.txx | 10 |
2 files changed, 7 insertions, 5 deletions
diff --git a/build2/algorithm.cxx b/build2/algorithm.cxx index d39711b..1c5b6a6 100644 --- a/build2/algorithm.cxx +++ b/build2/algorithm.cxx @@ -172,7 +172,7 @@ namespace build2 offset == target::offset_matched); } - return target_lock (a, &t, offset); + return target_lock {a, &t, offset}; } void diff --git a/build2/scheduler.txx b/build2/scheduler.txx index c7e6ef2..dd98b4a 100644 --- a/build2/scheduler.txx +++ b/build2/scheduler.txx @@ -66,6 +66,12 @@ namespace build2 typename task::args_type (decay_copy (forward<A> (a))...)}; td->thunk = &task_thunk<F, A...>; + + // Increment the task count. This has to be done under lock to prevent + // the task from decrementing the count before we had a chance to + // increment it. + // + task_count.fetch_add (1, std::memory_order_release); } else { @@ -98,10 +104,6 @@ namespace build2 } } - // Increment the task count. - // - task_count.fetch_add (1, std::memory_order_release); - // If there is a spare active thread, wake up (or create) the helper // (unless someone already snatched it). // |