1
0
Fork 0
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:
Eelco Dolstra 2017-10-09 15:07:07 +02:00
parent 838509d1a0
commit fda7b95cb0
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
2 changed files with 57 additions and 33 deletions

View file

@ -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