From 50be4c0e935f0018ddc146dafd1ef2cf948ff780 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 12 Feb 2018 13:37:45 +0200 Subject: Fix task_count handling race in scheduler --- build2/scheduler.txx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'build2/scheduler.txx') 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))...)}; td->thunk = &task_thunk; + + // 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). // -- cgit v1.1