mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +02:00
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.
This commit is contained in:
parent
838509d1a0
commit
fda7b95cb0
2 changed files with 57 additions and 33 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue