aboutsummaryrefslogtreecommitdiff
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
parentc0d6d431dfcdbf3883881f2feb88127c3ddf9ade (diff)
Fix task_count handling race in scheduler
-rw-r--r--build2/algorithm.cxx2
-rw-r--r--build2/scheduler.txx10
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).
//