Fixed possible leak in sf::Thread implementation (thread handles could be lost if the same sf::Thread was launched again before finishing)

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1441 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
LaurentGom 2010-03-05 10:35:13 +00:00
parent dec1820537
commit b3ca862273
2 changed files with 8 additions and 4 deletions

View File

@ -61,8 +61,7 @@ myUserData(UserData)
Thread::~Thread() Thread::~Thread()
{ {
// Wait for the thread to finish before destroying the instance // Wait for the thread to finish before destroying the instance
if (myIsActive) Wait();
Wait();
} }
@ -71,6 +70,9 @@ Thread::~Thread()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Thread::Launch() void Thread::Launch()
{ {
// Wait for the thread to finish, in case it was already running
Wait();
// Create the thread // Create the thread
myIsActive = true; myIsActive = true;
int Error = pthread_create(&myThread, NULL, &Thread::ThreadFunc, this); int Error = pthread_create(&myThread, NULL, &Thread::ThreadFunc, this);

View File

@ -62,8 +62,7 @@ myUserData(UserData)
Thread::~Thread() Thread::~Thread()
{ {
// Wait for the thread to finish before destroying the instance // Wait for the thread to finish before destroying the instance
if (myHandle) Wait();
Wait();
} }
@ -72,6 +71,9 @@ Thread::~Thread()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Thread::Launch() void Thread::Launch()
{ {
// Wait for the thread to finish, in case it was already running
Wait();
// Create the thread // Create the thread
myHandle = reinterpret_cast<HANDLE>(_beginthreadex(NULL, 0, &Thread::ThreadFunc, this, 0, NULL)); myHandle = reinterpret_cast<HANDLE>(_beginthreadex(NULL, 0, &Thread::ThreadFunc, this, 0, NULL));