Create new threads suspended on Windows and WP to prevent a race condition

This commit is contained in:
Cameron Gutman 2014-04-06 20:53:39 -04:00 committed by Michelle Bergeron
parent cdf07e6905
commit 929487249d
2 changed files with 10 additions and 1 deletions

View File

@ -157,7 +157,7 @@ int PltCreateThread(ThreadEntry entry, void* context, PLT_THREAD *thread) {
return -1;
}
thread->cancelled = 0;
thread->handle = CreateThread(NULL, 0, ThreadProc, ctx, 0, &thread->tid);
thread->handle = CreateThread(NULL, 0, ThreadProc, ctx, CREATE_SUSPENDED, &thread->tid);
if (thread->handle == NULL) {
CloseHandle(thread->termevent);
free(ctx);
@ -170,6 +170,9 @@ int PltCreateThread(ThreadEntry entry, void* context, PLT_THREAD *thread) {
thread_head = thread;
PltUnlockMutex(&thread_list_lock);
// Now the thread can run
ResumeThread(thread->handle);
err = 0;
}
}

View File

@ -40,6 +40,12 @@ CreateThread(
_In_ DWORD dwCreationFlags,
_Out_opt_ LPDWORD lpThreadId
);
DWORD
WINAPI
ResumeThread(
_In_ HANDLE hThread
);
#endif
int initializePlatformThreads(void);