Skip to content
Browse files

Windows should use _beginthreadex() instead of CreateThread(), to avo…

…id a

 memory leak on each joined thread.
  • Loading branch information
icculus committed Jan 4, 2006
1 parent 0364cdd commit fcf006780e5c55d88192d53b72019ae6a8260315
Showing with 13 additions and 4 deletions.
  1. +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)

int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
DWORD threadnum;

thread->handle = CreateThread(NULL, 0, RunThread, args, 0, &threadnum);
unsigned threadid;

* Avoid CreateThread:
* 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");

0 comments on commit fcf0067

Please sign in to comment.