Skip to content
Snippets Groups Projects
Commit b81df7e0 authored by Craig Tiller's avatar Craig Tiller
Browse files

Fix an obvious bug

And make it easy not to make the same mistake
parent b1663e74
No related branches found
No related tags found
No related merge requests found
......@@ -41,8 +41,10 @@ ThreadPool::ThreadPool(int num_threads) {
for (;;) {
std::unique_lock<std::mutex> lock(mu_);
// Wait until work is available or we are shutting down.
if (!shutdown_ || callbacks_.empty())
cv_.wait(lock, [=]() { return shutdown_ || !callbacks_.empty(); });
auto have_work = [=]() { return shutdown_ || !callbacks_.empty(); };
if (!have_work()) {
cv_.wait(lock, have_work);
}
// Drain callbacks before considering shutdown to ensure all work
// gets completed.
if (!callbacks_.empty()) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment