Commit 72c870cf authored by Ryan C. Gordon's avatar Ryan C. Gordon

Windows should use _beginthreadex() instead of CreateThread(), to avoid a

 memory leak on each joined thread.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401228
parent 4b43b304
......@@ -30,13 +30,14 @@ 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);
......@@ -44,9 +45,17 @@ static DWORD WINAPI RunThread(LPVOID 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: 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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment