diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2017-10-09 15:07:07 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2017-10-09 15:41:09 +0200 |
commit | fda7b95cb08c447a7ee4ec18ea3574d76e6264df (patch) | |
tree | e83f41f651ab2ed32fd5adb3110d326e8a1d5766 /src/libutil/thread-pool.hh | |
parent | 838509d1a085b8f7dc5474e13cfce3fbe3c47166 (diff) |
Fix a hang in ThreadPool
The worker threads could exit prematurely if they finished processing
all items while the main thread was still adding items. In particular,
this caused hanging nix-store --serve processes in the build farm.
Also, process items from the main thread.
Diffstat (limited to 'src/libutil/thread-pool.hh')
-rw-r--r-- | src/libutil/thread-pool.hh | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/libutil/thread-pool.hh b/src/libutil/thread-pool.hh index 06a097ab5..bb16b639a 100644 --- a/src/libutil/thread-pool.hh +++ b/src/libutil/thread-pool.hh @@ -44,19 +44,22 @@ private: struct State { - std::queue<work_t> left; + std::queue<work_t> pending; size_t active = 0; std::exception_ptr exception; std::vector<std::thread> workers; + bool draining = false; }; std::atomic_bool quit{false}; Sync<State> state_; - std::condition_variable work, done; + std::condition_variable work; - void workerEntry(); + void doWork(bool mainThread); + + void shutdown(); }; /* Process in parallel a set of items of type T that have a partial |