From 929487249d040208fcce1b731648e4acf6b2f96b Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 6 Apr 2014 20:53:39 -0400 Subject: [PATCH] Create new threads suspended on Windows and WP to prevent a race condition --- limelight-common/PlatformThreads.c | 5 ++++- limelight-common/PlatformThreads.h | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/limelight-common/PlatformThreads.c b/limelight-common/PlatformThreads.c index 8113912..71ca562 100644 --- a/limelight-common/PlatformThreads.c +++ b/limelight-common/PlatformThreads.c @@ -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; } } diff --git a/limelight-common/PlatformThreads.h b/limelight-common/PlatformThreads.h index dec8841..2a30205 100644 --- a/limelight-common/PlatformThreads.h +++ b/limelight-common/PlatformThreads.h @@ -40,6 +40,12 @@ CreateThread( _In_ DWORD dwCreationFlags, _Out_opt_ LPDWORD lpThreadId ); + +DWORD +WINAPI +ResumeThread( + _In_ HANDLE hThread +); #endif int initializePlatformThreads(void);