Added an assert in Thread::Wait() if the thread tries to wait for itself
This commit is contained in:
parent
d497401e3a
commit
5469eaa8c0
@ -28,6 +28,7 @@
|
||||
#include <SFML/System/Unix/ThreadImpl.hpp>
|
||||
#include <SFML/System/Thread.hpp>
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <SFML/System/Win32/ThreadImpl.hpp>
|
||||
#include <SFML/System/Thread.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <cassert>
|
||||
#include <process.h>
|
||||
|
||||
|
||||
@ -38,7 +39,7 @@ namespace priv
|
||||
////////////////////////////////////////////////////////////
|
||||
ThreadImpl::ThreadImpl(Thread* owner)
|
||||
{
|
||||
myThread = reinterpret_cast<HANDLE>(_beginthreadex(NULL, 0, &ThreadImpl::EntryPoint, owner, 0, NULL));
|
||||
myThread = reinterpret_cast<HANDLE>(_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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -87,6 +87,7 @@ private :
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
HANDLE myThread; ///< Win32 thread handle
|
||||
unsigned int myThreadId; ///< Win32 thread identifier
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
Loading…
Reference in New Issue
Block a user