From 5469eaa8c021cca3fb2e61c5d59f8a054b458f87 Mon Sep 17 00:00:00 2001 From: Laurent Gomila Date: Tue, 14 Jun 2011 17:49:33 +0200 Subject: [PATCH] Added an assert in Thread::Wait() if the thread tries to wait for itself --- src/SFML/System/Unix/ThreadImpl.cpp | 4 ++++ src/SFML/System/Win32/ThreadImpl.cpp | 6 +++++- src/SFML/System/Win32/ThreadImpl.hpp | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/SFML/System/Unix/ThreadImpl.cpp b/src/SFML/System/Unix/ThreadImpl.cpp index 0b4b1a24..c85396a5 100644 --- a/src/SFML/System/Unix/ThreadImpl.cpp +++ b/src/SFML/System/Unix/ThreadImpl.cpp @@ -28,6 +28,7 @@ #include #include #include +#include namespace sf @@ -49,7 +50,10 @@ myIsActive(true) void ThreadImpl::Wait() { if (myIsActive) + { + assert(pthread_equal(pthread_self(), myThread) == 0); // A thread cannot wait for itself! pthread_join(myThread, NULL); + } } diff --git a/src/SFML/System/Win32/ThreadImpl.cpp b/src/SFML/System/Win32/ThreadImpl.cpp index cc1ff653..6cc09957 100644 --- a/src/SFML/System/Win32/ThreadImpl.cpp +++ b/src/SFML/System/Win32/ThreadImpl.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -38,7 +39,7 @@ namespace priv //////////////////////////////////////////////////////////// ThreadImpl::ThreadImpl(Thread* owner) { - myThread = reinterpret_cast(_beginthreadex(NULL, 0, &ThreadImpl::EntryPoint, owner, 0, NULL)); + myThread = reinterpret_cast(_beginthreadex(NULL, 0, &ThreadImpl::EntryPoint, owner, 0, &myThreadId)); if (!myThread) Err() << "Failed to create thread" << std::endl; @@ -57,7 +58,10 @@ ThreadImpl::~ThreadImpl() void ThreadImpl::Wait() { if (myThread) + { + assert(myThreadId != GetCurrentThreadId()); // A thread cannot wait for itself! WaitForSingleObject(myThread, INFINITE); + } } diff --git a/src/SFML/System/Win32/ThreadImpl.hpp b/src/SFML/System/Win32/ThreadImpl.hpp index 92142e01..f565ac1f 100644 --- a/src/SFML/System/Win32/ThreadImpl.hpp +++ b/src/SFML/System/Win32/ThreadImpl.hpp @@ -87,6 +87,7 @@ private : // Member data //////////////////////////////////////////////////////////// HANDLE myThread; ///< Win32 thread handle + unsigned int myThreadId; ///< Win32 thread identifier }; } // namespace priv