diff --git a/modules/beast_core/threads/beast_Thread.cpp b/modules/beast_core/threads/beast_Thread.cpp index 8e5e41f98f..b2c0184892 100644 --- a/modules/beast_core/threads/beast_Thread.cpp +++ b/modules/beast_core/threads/beast_Thread.cpp @@ -171,8 +171,10 @@ bool Thread::waitForThreadToExit (const int timeOutMilliseconds) const return true; } -void Thread::stopThread (const int timeOutMilliseconds) +bool Thread::stopThread (const int timeOutMilliseconds) { + bool cleanExit = true; + // agh! You can't stop the thread that's calling this method! How on earth // would that work?? bassert (getCurrentThreadId() != getThreadId()); @@ -185,21 +187,30 @@ void Thread::stopThread (const int timeOutMilliseconds) notify(); if (timeOutMilliseconds != 0) - waitForThreadToExit (timeOutMilliseconds); + { + cleanExit = waitForThreadToExit (timeOutMilliseconds); + } if (isThreadRunning()) { + bassert (! cleanExit); + // very bad karma if this point is reached, as there are bound to be // locks and events left in silly states when a thread is killed by force.. - bassertfalse; - Logger::writeToLog ("!! killing thread by force !!"); - killThread(); threadHandle = nullptr; threadId = 0; + + cleanExit = false; + } + else + { + cleanExit = true; } } + + return cleanExit; } //============================================================================== diff --git a/modules/beast_core/threads/beast_Thread.h b/modules/beast_core/threads/beast_Thread.h index 0315ab44e2..90cb3f7f0a 100644 --- a/modules/beast_core/threads/beast_Thread.h +++ b/modules/beast_core/threads/beast_Thread.h @@ -109,8 +109,10 @@ public: thread to finish before killing it by force. A negative value in here will wait forever. @see signalThreadShouldExit, threadShouldExit, waitForThreadToExit, isThreadRunning + + @returns true if the thread exits, or false if the timeout expires first. */ - void stopThread (int timeOutMilliseconds = -1); + bool stopThread (int timeOutMilliseconds = -1); //============================================================================== /** Returns true if the thread is currently active */