diff --git a/libs/openFrameworks/utils/ofThread.cpp b/libs/openFrameworks/utils/ofThread.cpp index 3b47074c0da..3ca6ea5adcb 100644 --- a/libs/openFrameworks/utils/ofThread.cpp +++ b/libs/openFrameworks/utils/ofThread.cpp @@ -9,7 +9,10 @@ //------------------------------------------------- -ofThread::ofThread(): _threadRunning(false), _mutexBlocks(true){ +ofThread::ofThread() +:_threadRunning(false) +,_mutexBlocks(true) +,threadBeingWaitedFor(false){ thread.setName("Thread " + ofToString(thread.id())); } @@ -106,6 +109,8 @@ void ofThread::stopThread(){ //------------------------------------------------- void ofThread::waitForThread(bool callStopThread, long milliseconds){ if(thread.isRunning()){ + threadBeingWaitedFor = true; + // tell thread to stop if(callStopThread){ stopThread(); @@ -199,6 +204,12 @@ void ofThread::run(){ // should loop endlessly. threadedFunction(); +#if !defined(TARGET_WIN32) && !defined(TARGET_ANDROID) + // FIXME: this won't be needed once we update POCO https://github.com/pocoproject/poco/issues/79 + if(!threadBeingWaitedFor){ //if threadedFunction() ended and the thread is not being waited for, detach it before exiting. + pthread_detach(pthread_self()); + } +#endif #ifdef TARGET_ANDROID attachResult = ofGetJavaVMPtr()->DetachCurrentThread(); #endif diff --git a/libs/openFrameworks/utils/ofThread.h b/libs/openFrameworks/utils/ofThread.h index 98e16c49a9d..0412141c3cb 100644 --- a/libs/openFrameworks/utils/ofThread.h +++ b/libs/openFrameworks/utils/ofThread.h @@ -360,4 +360,6 @@ class ofThread: protected Poco::Runnable { Poco::AtomicCounter _mutexBlocks; ///< \brief Should the mutex block? + bool threadBeingWaitedFor; + };