From be5ff68d585f5cde333227f714cd1c4402f5e1b4 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 5 Apr 2006 06:45:03 +0000 Subject: [PATCH] Fix race condition: thread->ThreadId is not necessarily assigned before StartThread is run. --- stepmania/src/arch/Threads/Threads_Win32.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stepmania/src/arch/Threads/Threads_Win32.cpp b/stepmania/src/arch/Threads/Threads_Win32.cpp index 7ec8965e30..87557d452d 100644 --- a/stepmania/src/arch/Threads/Threads_Win32.cpp +++ b/stepmania/src/arch/Threads/Threads_Win32.cpp @@ -158,14 +158,16 @@ ThreadImpl *MakeThread( int (*pFunc)(void *pData), void *pData, uint64_t *piThre thread->m_pFunc = pFunc; thread->m_pData = pData; - thread->ThreadHandle = CreateThread( NULL, 0, &StartThread, thread, 0, &thread->ThreadId ); + thread->ThreadHandle = CreateThread( NULL, 0, &StartThread, thread, CREATE_SUSPENDED, &thread->ThreadId ); *piThreadID = (uint64_t) thread->ThreadId; - ASSERT_M( thread->ThreadHandle, ssprintf("%s", werr_ssprintf(GetLastError(), "CreateThread")) ); int slot = GetOpenSlot( thread->ThreadId ); g_ThreadHandles[slot] = thread->ThreadHandle; + int iRet = ResumeThread( thread->ThreadHandle ); + ASSERT_M( iRet == 1, ssprintf("%s", werr_ssprintf(GetLastError(), "ResumeThread")) ); + return thread; }