aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Craig Tiller <craig.tiller@gmail.com>2015-02-01 22:15:43 -0800
committerGravatar Craig Tiller <craig.tiller@gmail.com>2015-02-01 22:15:43 -0800
commitb81df7e000ca4010589b6bee09c437a7e97118c1 (patch)
tree29208736e8f9f555d45c904433dd733a670c8990 /src
parentb1663e74657d045e6f35b87bcea107e68767345f (diff)
Fix an obvious bug
And make it easy not to make the same mistake
Diffstat (limited to 'src')
-rw-r--r--src/cpp/server/thread_pool.cc6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/cpp/server/thread_pool.cc b/src/cpp/server/thread_pool.cc
index 35d61244f2..20279592cb 100644
--- a/src/cpp/server/thread_pool.cc
+++ b/src/cpp/server/thread_pool.cc
@@ -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()) {