diff --git a/include/SFML/System/Thread.hpp b/include/SFML/System/Thread.hpp index 938f46aef..b3eec7c0b 100644 --- a/include/SFML/System/Thread.hpp +++ b/include/SFML/System/Thread.hpp @@ -152,6 +152,8 @@ public : /// thread's function ends. /// Warning: if the thread function never ends, the calling /// thread will block forever. + /// If this function is called from its owner thread, it + /// returns without doing anything. /// //////////////////////////////////////////////////////////// void Wait(); diff --git a/src/SFML/System/Win32/ThreadImpl.cpp b/src/SFML/System/Win32/ThreadImpl.cpp index cc1ff653c..56832fdb6 100644 --- a/src/SFML/System/Win32/ThreadImpl.cpp +++ b/src/SFML/System/Win32/ThreadImpl.cpp @@ -57,7 +57,12 @@ ThreadImpl::~ThreadImpl() void ThreadImpl::Wait() { 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); + } }