# HG changeset patch # User Ryan C. Gordon # Date 1136408509 0 # Node ID 09bc22169702306e690bc11f5421833aa62cd0b2 # Parent f033d9589ca119e2bf80300bf862ec372d581dc5 Windows should use _beginthreadex() instead of CreateThread(), to avoid a memory leak on each joined thread. diff -r f033d9589ca1 -r 09bc22169702 src/thread/win32/SDL_systhread.c --- 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 #include #include +#include #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);