فهرست منبع

Fix an obvious bug

And make it easy not to make the same mistake
Craig Tiller 11 سال پیش
والد
کامیت
b81df7e000
1فایلهای تغییر یافته به همراه4 افزوده شده و 2 حذف شده
  1. 4 2
      src/cpp/server/thread_pool.cc

+ 4 - 2
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()) {