From 48e30ea0e3b5b1d79f631219581b64da215492a8 Mon Sep 17 00:00:00 2001 From: Laurent Gomila Date: Sun, 12 Jun 2011 14:08:54 +0200 Subject: [PATCH] Made the behaviour of Thread::Wait consistent across implementations when called from its owner thread --- include/SFML/System/Thread.hpp | 2 ++ src/SFML/System/Win32/ThreadImpl.cpp | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/SFML/System/Thread.hpp b/include/SFML/System/Thread.hpp index 938f46ae..b3eec7c0 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 cc1ff653..56832fdb 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); + } }