activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1444955 - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/decaf/internal/util/concurrent/Threading.cpp test/decaf/lang/ThreadTest.cpp test/decaf/lang/ThreadTest.h
Date Mon, 11 Feb 2013 20:42:58 GMT
Author: tabish
Date: Mon Feb 11 20:42:57 2013
New Revision: 1444955

URL: http://svn.apache.org/r1444955
Log:
Fix for: https://issues.apache.org/jira/browse/AMQCPP-461

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/concurrent/Threading.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ThreadTest.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ThreadTest.h

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/concurrent/Threading.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/concurrent/Threading.cpp?rev=1444955&r1=1444954&r2=1444955&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/concurrent/Threading.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/concurrent/Threading.cpp
Mon Feb 11 20:42:57 2013
@@ -924,6 +924,22 @@ ThreadHandle* Threading::createNewThread
 void Threading::destroyThread(ThreadHandle* thread) {
 
     if (!thread->osThread) {
+
+        // If the thread was created but never started then we need to wake it
+        // up from the suspended state so that it can terminate, we mark it
+        // canceled to ensure it doesn't call its runnable.
+        if (thread->state == Thread::NEW) {
+            PlatformThread::lockMutex(thread->mutex);
+
+            if (thread->state == Thread::NEW && thread->suspended == true)
{
+                thread->canceled = true;
+                thread->suspended = false;
+                PlatformThread::notifyAll(thread->condition);
+            }
+
+            PlatformThread::unlockMutex(thread->mutex);
+        }
+
         try {
             Threading::join(thread, 0, 0);
         } catch (InterruptedException& ex) {}
@@ -1109,8 +1125,8 @@ bool Threading::join(ThreadHandle* threa
         interrupted = true;
     } else if (self == thread && self->state != Thread::TERMINATED) {
 
-        // When blocking on ourself, we just enter a wait and hope their's
-        // either a timeout, or we interrupted.
+        // When blocking on ourself, we just enter a wait and hope there's
+        // either a timeout, or we are interrupted.
 
         JoinCompletionCondition completion(self, NULL);
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ThreadTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ThreadTest.cpp?rev=1444955&r1=1444954&r2=1444955&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ThreadTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ThreadTest.cpp Mon Feb 11
20:42:57 2013
@@ -901,3 +901,23 @@ void ThreadTest::testConcurrentRapidCrea
 
     threads.clear();
 }
+
+////////////////////////////////////////////////////////////////////////////////
+void ThreadTest::testCreatedButNotStarted() {
+
+    RunThread runnable;
+
+    ArrayList<Thread*> threads;
+    const int NUM_THREADS = 32;
+
+    for (int i = 0; i < NUM_THREADS; ++i) {
+        threads.add(new Thread(&runnable));
+    }
+
+    Pointer<Iterator<Thread*> > threadsIter(threads.iterator());
+    while (threadsIter->hasNext()) {
+        delete threadsIter->next();
+    }
+
+    threads.clear();
+}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ThreadTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ThreadTest.h?rev=1444955&r1=1444954&r2=1444955&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ThreadTest.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ThreadTest.h Mon Feb 11 20:42:57
2013
@@ -55,6 +55,7 @@ namespace lang{
       CPPUNIT_TEST( testInterruptWait );
       CPPUNIT_TEST( testRapidCreateAndDestroy );
       CPPUNIT_TEST( testConcurrentRapidCreateAndDestroy );
+      CPPUNIT_TEST( testCreatedButNotStarted );
       CPPUNIT_TEST_SUITE_END();
 
     public:
@@ -92,6 +93,7 @@ namespace lang{
         void testInterruptWait();
         void testRapidCreateAndDestroy();
         void testConcurrentRapidCreateAndDestroy();
+        void testCreatedButNotStarted();
 
     };
 



Mime
View raw message