activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1415229 - /activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ThreadPoolExecutor.cpp
Date Thu, 29 Nov 2012 16:05:26 GMT
Author: tabish
Date: Thu Nov 29 16:05:26 2012
New Revision: 1415229

URL: http://svn.apache.org/viewvc?rev=1415229&view=rev
Log:
fix for: https://issues.apache.org/jira/browse/AMQCPP-405

safer ThreadPoolExecutor destructor logic. 

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ThreadPoolExecutor.cpp

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ThreadPoolExecutor.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ThreadPoolExecutor.cpp?rev=1415229&r1=1415228&r2=1415229&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ThreadPoolExecutor.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/ThreadPoolExecutor.cpp
Thu Nov 29 16:05:26 2012
@@ -244,13 +244,17 @@ namespace concurrent{
 
             virtual void run() {
                 kernel->mainLock.lock();
-                try{
-                    Pointer< Iterator<Worker*> > iter( kernel->deadWorkers.iterator()
);
-                    while(iter->hasNext()) {
-                        delete iter->next();
-                        iter->remove();
-                    }
-                } catch(...) {}
+
+                if (!kernel->isTerminated()) {
+                    try {
+                        Pointer< Iterator<Worker*> > iter( kernel->deadWorkers.iterator()
);
+                        while(iter->hasNext()) {
+                            delete iter->next();
+                            iter->remove();
+                        }
+                    } catch(...) {}
+                }
+
                 kernel->mainLock.unlock();
             }
         };
@@ -384,8 +388,16 @@ namespace concurrent{
 
                 // Turn off the cleanup timer first so that it doesn't fire while
                 // we transition all the remaining workers into the dead workers
-                // queue while can lead to lock contention.
-                this->cleanupTimer.cancel();
+                // queue while can lead to lock contention.  Its run method holds
+                // the mainLock so we need to wait for its release before moving on.
+                try {
+                    this->mainLock.lock();
+                    this->cleanupTimer.cancel();
+                    this->cleanupTimer.purge();
+                    this->mainLock.unlock();
+                } catch(Exception& ex) {
+                    this->mainLock.unlock();
+                }
 
                 this->shutdown();
                 this->awaitTermination();



Mime
View raw message