summaryrefslogtreecommitdiff
path: root/rts/win32/OSThreads.c
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2011-11-08 16:28:57 +0000
committerSimon Marlow <marlowsd@gmail.com>2011-11-09 09:16:04 +0000
commitdad0d225ec5117b715efc0c44c4fa0d606660381 (patch)
tree9a8920b36e282794cbf713edfba50027bafb0859 /rts/win32/OSThreads.c
parent099bd6fc48eedb00229c01ca360cd54eedce8f81 (diff)
downloadhaskell-dad0d225ec5117b715efc0c44c4fa0d606660381.tar.gz
Close some handle leaks (#5604)
Also, use the Win32 API (CreateThread) instead of the CRT API (_beginthreadex) for thread creation.
Diffstat (limited to 'rts/win32/OSThreads.c')
-rw-r--r--rts/win32/OSThreads.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/rts/win32/OSThreads.c b/rts/win32/OSThreads.c
index 44db42fef4..c85dd2f854 100644
--- a/rts/win32/OSThreads.c
+++ b/rts/win32/OSThreads.c
@@ -93,20 +93,30 @@ yieldThread()
void
shutdownThread()
{
- _endthreadex(0);
- barf("_endthreadex returned"); // avoid gcc warning
+ ExitThread(0);
+ barf("ExitThread() returned"); // avoid gcc warning
}
int
createOSThread (OSThreadId* pId, OSThreadProc *startProc, void *param)
{
-
- return (_beginthreadex ( NULL, /* default security attributes */
- 0,
- (unsigned (__stdcall *)(void *)) startProc,
- param,
- 0,
- (unsigned*)pId) == 0);
+ HANDLE h;
+ h = CreateThread ( NULL, /* default security attributes */
+ 0,
+ (LPTHREAD_START_ROUTINE)startProc,
+ param,
+ 0,
+ pId);
+
+ if (h == 0) {
+ return 1;
+ } else {
+ // This handle leaks if we don't close it here. Perhaps we
+ // should try to keep it around to avoid needing OpenThread()
+ // later.
+ CloseHandle(h);
+ return 0;
+ }
}
OSThreadId
@@ -128,6 +138,7 @@ osThreadIsAlive(OSThreadId id)
sysErrorBelch("osThreadIsAlive: GetExitCodeThread");
stg_exit(EXIT_FAILURE);
}
+ CloseHandle(hdl);
return (exit_code == STILL_ACTIVE);
}
@@ -286,6 +297,7 @@ interruptOSThread (OSThreadId id)
} else {
// Nothing to do, unfortunately
}
+ CloseHandle(hdl);
}
#else /* !defined(THREADED_RTS) */