comparison src/thread/win32/SDL_systhread.c @ 1225:09bc22169702

Windows should use _beginthreadex() instead of CreateThread(), to avoid a memory leak on each joined thread.
author Ryan C. Gordon <icculus@icculus.org>
date Wed, 04 Jan 2006 21:01:49 +0000
parents b8d311d90021
children 86d0d01290ea
comparison
equal deleted inserted replaced
1224:f033d9589ca1 1225:09bc22169702
28 /* Win32 thread management routines for SDL */ 28 /* Win32 thread management routines for SDL */
29 29
30 #include <stdio.h> 30 #include <stdio.h>
31 #include <stdlib.h> 31 #include <stdlib.h>
32 #include <windows.h> 32 #include <windows.h>
33 #include <process.h>
33 34
34 #include "SDL_error.h" 35 #include "SDL_error.h"
35 #include "SDL_thread.h" 36 #include "SDL_thread.h"
36 #include "SDL_systhread.h" 37 #include "SDL_systhread.h"
37 38
38 39
39 static DWORD WINAPI RunThread(LPVOID data) 40 static unsigned __stdcall RunThread(void *data)
40 { 41 {
41 SDL_RunThread(data); 42 SDL_RunThread(data);
42 return(0); 43 return(0);
43 } 44 }
44 45
45 int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) 46 int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
46 { 47 {
47 DWORD threadnum; 48 unsigned threadid;
48 49
49 thread->handle = CreateThread(NULL, 0, RunThread, args, 0, &threadnum); 50 /*
51 * Avoid CreateThread: https://bugzilla.libsdl.org/show_bug.cgi?id=22
52 *
53 * have to use _beginthreadex if we want the returned handle
54 * to be accessible after the thread exits
55 * threads created with _beginthread auto-close the handle
56 */
57 thread->handle = (SYS_ThreadHandle) _beginthreadex(NULL, 0, RunThread,
58 args, 0, &threadid);
50 if (thread->handle == NULL) { 59 if (thread->handle == NULL) {
51 SDL_SetError("Not enough resources to create thread"); 60 SDL_SetError("Not enough resources to create thread");
52 return(-1); 61 return(-1);
53 } 62 }
54 return(0); 63 return(0);