You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2009/12/03 01:28:49 UTC

svn commit: r886347 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads: CompositeTaskRunner.cpp DedicatedTaskRunner.cpp

Author: tabish
Date: Thu Dec  3 00:28:46 2009
New Revision: 886347

URL: http://svn.apache.org/viewvc?rev=886347&view=rev
Log:
Add code to allow the TaskRunner to be shutdown from its own tasks thread, otherwise there's a risk of a deadlock should the user create code that allows this path to execute.  This was causing a deadlock on Windows when testing the inactivity monitor and a read error was detected asynchronously. 

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/CompositeTaskRunner.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/DedicatedTaskRunner.cpp

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/CompositeTaskRunner.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/CompositeTaskRunner.cpp?rev=886347&r1=886346&r2=886347&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/CompositeTaskRunner.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/CompositeTaskRunner.cpp Thu Dec  3 00:28:46 2009
@@ -59,7 +59,7 @@
 
         // Wait till the thread stops ( no need to wait if shutdown
         // is called from thread that is shutting down)
-        if( !threadTerminated ) {
+        if( Thread::currentThread() != this->thread.get() && !threadTerminated ) {
             mutex.wait( timeout );
         }
     }
@@ -74,8 +74,9 @@
         mutex.notifyAll();
     }
 
-    // Wait till the thread stops
-    if( !threadTerminated ) {
+    // Wait till the thread stops ( no need to wait if shutdown
+    // is called from thread that is shutting down)
+    if( Thread::currentThread() != this->thread.get() && !threadTerminated ) {
         this->thread->join();
     }
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/DedicatedTaskRunner.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/DedicatedTaskRunner.cpp?rev=886347&r1=886346&r2=886347&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/DedicatedTaskRunner.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/threads/DedicatedTaskRunner.cpp Thu Dec  3 00:28:46 2009
@@ -60,7 +60,7 @@
 
         // Wait till the thread stops ( no need to wait if shutdown
         // is called from thread that is shutting down)
-        if( !threadTerminated ) {
+        if( Thread::currentThread() != this->thread.get() && !threadTerminated ) {
             mutex.wait( timeout );
         }
     }
@@ -75,8 +75,9 @@
         mutex.notifyAll();
     }
 
-    // Wait till the thread stops
-    if( !threadTerminated ) {
+    // Wait till the thread stops ( no need to wait if shutdown
+    // is called from thread that is shutting down)
+    if( Thread::currentThread() != this->thread.get() && !threadTerminated ) {
         this->thread->join();
     }
 }