Return-Path: Delivered-To: apmail-geronimo-activemq-commits-archive@www.apache.org Received: (qmail 86567 invoked from network); 16 Dec 2006 20:58:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 16 Dec 2006 20:58:13 -0000 Received: (qmail 55147 invoked by uid 500); 16 Dec 2006 20:58:21 -0000 Delivered-To: apmail-geronimo-activemq-commits-archive@geronimo.apache.org Received: (qmail 55127 invoked by uid 500); 16 Dec 2006 20:58:20 -0000 Mailing-List: contact activemq-commits-help@geronimo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: activemq-dev@geronimo.apache.org Delivered-To: mailing list activemq-commits@geronimo.apache.org Received: (qmail 55118 invoked by uid 99); 16 Dec 2006 20:58:20 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Dec 2006 12:58:20 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Dec 2006 12:58:12 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id C872A1A981A; Sat, 16 Dec 2006 12:57:25 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r487881 - /incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/concurrent/Thread.cpp Date: Sat, 16 Dec 2006 20:57:25 -0000 To: activemq-commits@geronimo.apache.org From: nmittler@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061216205725.C872A1A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 }