Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Windows should use _beginthreadex() instead of CreateThread(), to avo…
…id a
memory leak on each joined thread.
- Loading branch information
Showing
with
13 additions
and
4 deletions.
-
+13
−4
src/thread/win32/SDL_systhread.c
|
@@ -30,23 +30,32 @@ static char rcsid = |
|
|
#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); |
|
|
} |
|
|
|
|
|
int SDL_SYS_CreateThread(SDL_Thread *thread, void *args) |
|
|
{ |
|
|
DWORD threadnum; |
|
|
|
|
|
thread->handle = CreateThread(NULL, 0, RunThread, args, 0, &threadnum); |
|
|
unsigned threadid; |
|
|
|
|
|
/* |
|
|
* 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); |
|
|