You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by nm...@apache.org on 2006/12/16 21:57:25 UTC

svn commit: r487881 - /incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/concurrent/Thread.cpp

Author: nmittler
Date: Sat Dec 16 12:57:24 2006
New Revision: 487881

URL: http://svn.apache.org/viewvc?view=rev&rev=487881
Log:
[AMQCPP-27] Adding CloseHandle to Thread to free thread resource in win32.

Modified:
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/concurrent/Thread.cpp

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/concurrent/Thread.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/concurrent/Thread.cpp?view=diff&rev=487881&r1=487880&r2=487881
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/concurrent/Thread.cpp (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/concurrent/Thread.cpp Sat Dec 16 12:57:24 2006
@@ -36,8 +36,8 @@
     pthread_attr_t threadAttribute;
     // Static Initializer:
     ThreadStaticInitializer() {
-        pthread_attr_init (&threadAttribute);
-        pthread_attr_setdetachstate (&threadAttribute, PTHREAD_CREATE_JOINABLE);
+        ::pthread_attr_init (&threadAttribute);
+        ::pthread_attr_setdetachstate (&threadAttribute, PTHREAD_CREATE_JOINABLE);
     }
 } threadStaticInitializer;
 #endif
@@ -73,9 +73,9 @@
     
 #ifdef unix
     
-    pthread_attr_init (&attributes);
-    pthread_attr_setdetachstate (&attributes, PTHREAD_CREATE_JOINABLE);
-    int err = pthread_create (
+    ::pthread_attr_init (&attributes);
+    ::pthread_attr_setdetachstate (&attributes, PTHREAD_CREATE_JOINABLE);
+    int err = ::pthread_create (
         &this->threadHandle,
         &attributes,
         runCallback,
@@ -89,7 +89,7 @@
 
     unsigned int threadId = 0;
     this->threadHandle = 
-        (HANDLE)_beginthreadex(NULL, 0, runCallback, this, 0, &threadId);
+        (HANDLE)::_beginthreadex(NULL, 0, runCallback, this, 0, &threadId);
     if (this->threadHandle == NULL) {
         throw exceptions::ActiveMQException( __FILE__, __LINE__,
             "Coud not start thread");
@@ -111,9 +111,9 @@
     if (!this->joined) {
         
 #ifdef unix
-        pthread_join(this->threadHandle, NULL);
+        ::pthread_join(this->threadHandle, NULL);
 #else
-        WaitForSingleObject (this->threadHandle, INFINITE);       
+        ::WaitForSingleObject (this->threadHandle, INFINITE);       
 #endif
 
     }
@@ -134,7 +134,7 @@
     }
     
 #else
-    Sleep (millisecs);
+    ::Sleep (millisecs);
 #endif
 }
 
@@ -165,8 +165,14 @@
 #ifdef unix
     return NULL;
 #else
-    // Return 0 if no exception was threwn. Otherwise -1.
-    _endthreadex(0); // Needed when using threads and CRT in Windows. Otherwise memleak can appear.
+
+    // Needed when using threads and CRT in Windows. Otherwise memleak can appear.
+    ::_endthreadex(0); 
+    
+    // _endthreadex (unlike _endthread) does not automatically close the thread handle
+    // so we need to do this manually.
+    ::CloseHandle(thread->threadHandle);
+    
     return 0;
 #endif
 }