diff --git a/src/zm_thread.cpp b/src/zm_thread.cpp index 09cf0da3f..4e05156a0 100644 --- a/src/zm_thread.cpp +++ b/src/zm_thread.cpp @@ -253,7 +253,7 @@ void *Thread::mThreadFunc( void *arg ) Debug( 2, "Invoking thread" ); Thread *thisPtr = (Thread *)arg; - void *status = 0; + thisPtr->status = 0; try { thisPtr->mThreadMutex.lock(); @@ -261,19 +261,18 @@ void *Thread::mThreadFunc( void *arg ) thisPtr->mThreadCondition.signal(); thisPtr->mThreadMutex.unlock(); thisPtr->mRunning = true; - int run=(thisPtr->run()); - status = (void *)&run; + thisPtr->status = thisPtr->run(); thisPtr->mRunning = false; - Debug( 2, "Exiting thread, status %p", status ); + Debug( 2, "Exiting thread, status %p", (void *)&(thisPtr->status) ); + return (void *)&(thisPtr->status); } catch ( const ThreadException &e ) { Error( "%s", e.getMessage().c_str() ); thisPtr->mRunning = false; - status = (void *)-1; - Debug( 2, "Exiting thread after exception, status %p", status ); + Debug( 2, "Exiting thread after exception, status %p", (void *)-1 ); + return (void *)-1; } - return( status ); } void Thread::start() diff --git a/src/zm_thread.h b/src/zm_thread.h index 615bec6aa..de2b1a6e4 100644 --- a/src/zm_thread.h +++ b/src/zm_thread.h @@ -224,6 +224,7 @@ protected: #endif bool mStarted; bool mRunning; + int status; // Used in various funcions to get around return a local variable protected: Thread(); @@ -253,10 +254,10 @@ return tid; return( pthread_self() ); } #endif - void exit( int status = 0 ) + void exit( int p_status = 0 ) { //INFO( "Exiting" ); - pthread_exit( (void *)&status ); + pthread_exit( (void *)&p_status ); } static void *mThreadFunc( void *arg );