You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by dr...@apache.org on 2010/03/09 06:20:01 UTC

svn commit: r920680 - /incubator/thrift/trunk/lib/cpp/src/concurrency/ThreadManager.cpp

Author: dreiss
Date: Tue Mar  9 05:20:01 2010
New Revision: 920680

URL: http://svn.apache.org/viewvc?rev=920680&view=rev
Log:
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.

Modified:
    incubator/thrift/trunk/lib/cpp/src/concurrency/ThreadManager.cpp

Modified: incubator/thrift/trunk/lib/cpp/src/concurrency/ThreadManager.cpp
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cpp/src/concurrency/ThreadManager.cpp?rev=920680&r1=920679&r2=920680&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/cpp/src/concurrency/ThreadManager.cpp (original)
+++ incubator/thrift/trunk/lib/cpp/src/concurrency/ThreadManager.cpp Tue Mar  9 05:20:01 2010
@@ -295,7 +295,7 @@ class ThreadManager::Worker: public Runn
             /* 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();
             }
           }