Skip to content

Commit

Permalink
Windows should use _beginthreadex() instead of CreateThread(), to avo…
Browse files Browse the repository at this point in the history
…id a

 memory leak on each joined thread.
  • Loading branch information
icculus committed Jan 4, 2006
1 parent 0364cdd commit fcf0067
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/thread/win32/SDL_systhread.c
Expand Up @@ -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);
Expand Down

0 comments on commit fcf0067

Please sign in to comment.