Fix an obvious bug

And make it easy not to make the same mistake
pull/325/head
Craig Tiller 10 years ago
parent b1663e7465
commit b81df7e000
  1. 6
      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()) {

Loading…
Cancel
Save