From 4cc0755b3382abc3e17ebba0ab4c2c78b9a8bbd7 Mon Sep 17 00:00:00 2001 From: David Reiss Date: Tue, 9 Mar 2010 05:20:01 +0000 Subject: [PATCH] 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 --- lib/cpp/src/concurrency/ThreadManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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(); } } -- 2.17.1