changeset 1225:09bc22169702

Windows should use _beginthreadex() instead of CreateThread(), to avoid a memory leak on each joined thread.
author Ryan C. Gordon <icculus@icculus.org>
date Wed, 04 Jan 2006 21:01:49 +0000
parents f033d9589ca1
children d05306f0dc21
files src/thread/win32/SDL_systhread.c
diffstat 1 files changed, 12 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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 <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 @@
 
 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);