aboutsummaryrefslogtreecommitdiff
path: root/build2/scheduler.txx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-02-12 13:37:45 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2018-02-12 13:37:45 +0200
commit50be4c0e935f0018ddc146dafd1ef2cf948ff780 (patch)
tree7ba754af702d5ef98aac595334fb2bf1fbe0fa47 /build2/scheduler.txx
parentc0d6d431dfcdbf3883881f2feb88127c3ddf9ade (diff)
Fix task_count handling race in scheduler
Diffstat (limited to 'build2/scheduler.txx')
-rw-r--r--build2/scheduler.txx10
1 files changed, 6 insertions, 4 deletions
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).
//