activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1064906 - /activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.cpp
Date Fri, 28 Jan 2011 22:00:41 GMT
Author: tabish
Date: Fri Jan 28 22:00:41 2011
New Revision: 1064906

URL: http://svn.apache.org/viewvc?rev=1064906&view=rev
Log:
possible fix for:

https://issues.apache.org/jira/browse/AMQCPP-294
https://issues.apache.org/jira/browse/AMQCPP-298

Incorrect use of pthread_detach causes segfault on OSX

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.cpp

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.cpp?rev=1064906&r1=1064905&r2=1064906&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.cpp Fri Jan 28 22:00:41
2011
@@ -188,7 +188,9 @@ namespace{
             ThreadProperties::runCallback( properties );
 
             pthread_setspecific( currentThreadKey, NULL );
-            pthread_detach( properties->handle );
+
+            //pthread_detach( properties->handle );
+            pthread_exit(NULL);
 
             properties->state = Thread::TERMINATED;
 
@@ -333,6 +335,14 @@ void Thread::initialize( Runnable* task,
 ////////////////////////////////////////////////////////////////////////////////
 Thread::~Thread() {
     try{
+
+        #ifdef HAVE_PTHREAD_H
+            void* theReturn = 0;
+            pthread_join( properties->handle, &theReturn );
+        #else
+            ::WaitForSingleObject( properties->handle, INFINITE );
+        #endif
+
         delete this->properties;
     }
     DECAF_CATCH_NOTHROW( Exception )
@@ -417,18 +427,18 @@ void Thread::start() {
 ////////////////////////////////////////////////////////////////////////////////
 void Thread::join() {
 
-    if( this->properties->state < Thread::RUNNABLE ) {
+    if( this->properties->state == Thread::TERMINATED ) {
         return;
     }
 
-    if( this->properties->state != Thread::TERMINATED ) {
+    synchronized( &this->properties->mutex ) {
 
-        #ifdef HAVE_PTHREAD_H
-            void* theReturn = 0;
-            pthread_join( properties->handle, &theReturn );
-        #else
-            ::WaitForSingleObject( properties->handle, INFINITE );
-        #endif
+        if( this->properties->state < Thread::RUNNABLE ||
+            this->properties->state == Thread::TERMINATED ) {
+            return;
+        }
+
+        this->properties->mutex.wait();
     }
 }
 
@@ -441,10 +451,6 @@ void Thread::join( long long millisecs )
             "Thread::join( millisecs ) - Value given {%d} is less than 0", millisecs );
     }
 
-    if( this->properties->state < Thread::RUNNABLE ) {
-        return;
-    }
-
     this->join( millisecs, 0 );
 }
 
@@ -463,9 +469,14 @@ void Thread::join( long long millisecs, 
             "Thread::join( millisecs, nanos ) - Nanoseconds must be in range [0...999999]"
);
     }
 
+    if( this->properties->state == Thread::TERMINATED ) {
+        return;
+    }
+
     synchronized( &this->properties->mutex ) {
 
-        if( this->properties->state < Thread::RUNNABLE ) {
+        if( this->properties->state < Thread::RUNNABLE ||
+            this->properties->state == Thread::TERMINATED ) {
             return;
         }
 



Mime
View raw message