src/thread/win32/SDL_systhread.c
changeset 1225 09bc22169702
parent 769 b8d311d90021
child 1251 86d0d01290ea
--- a/src/thread/win32/SDL_systhread.c	Wed Jan 04 20:53:55 2006 +0000
+++ b/src/thread/win32/SDL_systhread.c	Wed Jan 04 21:01:49 2006 +0000
@@ -30,13 +30,14 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <windows.h>
+#include <process.h>
 
 #include "SDL_error.h"
 #include "SDL_thread.h"
 #include "SDL_systhread.h"
 
 
-static DWORD WINAPI RunThread(LPVOID data)
+static unsigned __stdcall RunThread(void *data)
 {
 	SDL_RunThread(data);
 	return(0);
@@ -44,9 +45,17 @@
 
 int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
 {
-	DWORD  threadnum;
+	unsigned threadid;
 
-	thread->handle = CreateThread(NULL, 0, RunThread, args, 0, &threadnum);
+	/*
+	 * Avoid CreateThread: https://bugzilla.libsdl.org/show_bug.cgi?id=22
+	 *
+	 * have to use _beginthreadex if we want the returned handle
+	 * to be accessible after the thread exits
+	 * threads created with _beginthread auto-close the handle
+	 */
+	thread->handle = (SYS_ThreadHandle) _beginthreadex(NULL, 0, RunThread,
+			args, 0, &threadid);
 	if (thread->handle == NULL) {
 		SDL_SetError("Not enough resources to create thread");
 		return(-1);