From 28e325f0bd58bf11bd66997fff041d46b89b1cf1 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 10 Oct 2017 19:40:57 +0200 Subject: Fix thread hygine issue --- build2/scheduler.cxx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'build2/scheduler.cxx') 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 (); -- cgit v1.1