From: David Reiss Date: Tue, 9 Mar 2010 05:20:01 +0000 (+0000) Subject: cpp: Fix a race/deadlock in ThreadManager X-Git-Tag: 0.3.0~79 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=4cc0755b3382abc3e17ebba0ab4c2c78b9a8bbd7;p=common%2Fthrift.git cpp: Fix a race/deadlock in ThreadManager When removing a task from the pending queue, we were only notifying a blocked thread waiting to enqueue a task if the number of pending tasks was exactly one less than the limit. However, if two tasks are finished at about the same time, this can result in two spots being freed up with only one notify. With this change, we always notify on task completion, eliminating the race/deadlock. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@920680 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/cpp/src/concurrency/ThreadManager.cpp b/lib/cpp/src/concurrency/ThreadManager.cpp index d0bb41f5..aee57f31 100644 --- a/lib/cpp/src/concurrency/ThreadManager.cpp +++ b/lib/cpp/src/concurrency/ThreadManager.cpp @@ -295,7 +295,7 @@ class ThreadManager::Worker: public Runnable { /* If we have a pending task max and we just dropped below it, wakeup any thread that might be blocked on add. */ if (manager_->pendingTaskCountMax_ != 0 && - manager_->tasks_.size() == manager_->pendingTaskCountMax_ - 1) { + manager_->tasks_.size() <= manager_->pendingTaskCountMax_ - 1) { manager_->maxMonitor_.notify(); } }