aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-10-10 19:40:57 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-10-10 19:40:57 +0200
commit28e325f0bd58bf11bd66997fff041d46b89b1cf1 (patch)
tree2b65caa32829fe549c10789750b1fab4c11cb4fd
parentac82bded6b2bdaf1e04b6357415c9f5ce04063dd (diff)
Fix thread hygine issue
-rw-r--r--build2/scheduler.cxx10
1 files changed, 8 insertions, 2 deletions
diff --git a/build2/scheduler.cxx b/build2/scheduler.cxx
index 65684eb..86dbd5c 100644
--- a/build2/scheduler.cxx
+++ b/build2/scheduler.cxx
@@ -479,12 +479,18 @@ namespace build2
size_t n (s.task_queues_.size ()); // Different to end().
l.unlock ();
- for (size_t i (0); i != n; ++i)
+ // Note: we have to be careful not to advance the iterator past the
+ // last element (since what's past could be changing).
+ //
+ for (size_t i (0);; ++it)
{
- task_queue& tq (*it++);
+ task_queue& tq (*it);
for (lock ql (tq.mutex); !tq.shutdown && !s.empty_front (tq); )
s.pop_front (tq, ql);
+
+ if (++i == n)
+ break;
}
l.lock ();