Made the behaviour of Thread::Wait consistent across implementations when called from its owner thread

This commit is contained in:
Laurent Gomila 2011-06-12 14:08:54 +02:00
parent b0ebca9d29
commit 48e30ea0e3
2 changed files with 8 additions and 1 deletions

View File

@ -152,6 +152,8 @@ public :
/// thread's function ends. /// thread's function ends.
/// Warning: if the thread function never ends, the calling /// Warning: if the thread function never ends, the calling
/// thread will block forever. /// thread will block forever.
/// If this function is called from its owner thread, it
/// returns without doing anything.
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Wait(); void Wait();

View File

@ -57,7 +57,12 @@ ThreadImpl::~ThreadImpl()
void ThreadImpl::Wait() void ThreadImpl::Wait()
{ {
if (myThread) if (myThread)
WaitForSingleObject(myThread, INFINITE); {
// The following condition avoids a deadlock if Wait() is called from its
// owner thread. This makes the behaviour consistent with the Unix implementation
if (GetThreadId(myThread) != GetCurrentThreadId())
WaitForSingleObject(myThread, INFINITE);
}
} }