diff options
author | Craig Tiller <craig.tiller@gmail.com> | 2015-02-01 22:15:43 -0800 |
---|---|---|
committer | Craig Tiller <craig.tiller@gmail.com> | 2015-02-01 22:15:43 -0800 |
commit | b81df7e000ca4010589b6bee09c437a7e97118c1 (patch) | |
tree | 29208736e8f9f555d45c904433dd733a670c8990 /src | |
parent | b1663e74657d045e6f35b87bcea107e68767345f (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.cc | 6 |
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()) { |