diff options
author | Ben Gamari <ben@smart-cactus.org> | 2020-03-10 22:55:19 -0400 |
---|---|---|
committer | Moritz Angermann <moritz.angermann@gmail.com> | 2020-09-18 08:06:00 +0000 |
commit | d81c7c84fa89f1c5a5d0d024c8b147287bc3ce01 (patch) | |
tree | b5ef85d7d936dfd4f5dec1c683d474e1d15a204e | |
parent | 80b2eb5b9c66092f0369904d2fc36ee2dba2304f (diff) | |
download | haskell-d81c7c84fa89f1c5a5d0d024c8b147287bc3ce01.tar.gz |
rts: Join to concurrent mark thread during shutdown
Previously we would take all capabilities but fail to join on the thread
itself, potentially resulting in a leaked thread.
-rw-r--r-- | includes/rts/OSThreads.h | 3 | ||||
-rw-r--r-- | rts/posix/OSThreads.c | 8 | ||||
-rw-r--r-- | rts/win32/OSThreads.c | 9 |
3 files changed, 19 insertions, 1 deletions
diff --git a/includes/rts/OSThreads.h b/includes/rts/OSThreads.h index d2c4a6a54e..f4fe361f41 100644 --- a/includes/rts/OSThreads.h +++ b/includes/rts/OSThreads.h @@ -171,7 +171,8 @@ typedef void* OSThreadProcAttr OSThreadProc(void *); extern int createOSThread ( OSThreadId* tid, char *name, OSThreadProc *startProc, void *param); extern bool osThreadIsAlive ( OSThreadId id ); -extern void interruptOSThread (OSThreadId id); +extern void interruptOSThread ( OSThreadId id ); +extern void joinOSThread ( OSThreadId id ); // // Condition Variables diff --git a/rts/posix/OSThreads.c b/rts/posix/OSThreads.c index c51ccfcafb..6347e8ce7a 100644 --- a/rts/posix/OSThreads.c +++ b/rts/posix/OSThreads.c @@ -398,6 +398,14 @@ interruptOSThread (OSThreadId id) pthread_kill(id, SIGPIPE); } +void +joinOSThread (OSThreadId id) +{ + if (pthread_join(id, NULL) != 0) { + sysErrorBelch("joinOSThread: error %d", errno); + } +} + KernelThreadId kernelThreadId (void) { #if defined(linux_HOST_OS) diff --git a/rts/win32/OSThreads.c b/rts/win32/OSThreads.c index c67d621bc2..d252ff4a2b 100644 --- a/rts/win32/OSThreads.c +++ b/rts/win32/OSThreads.c @@ -574,6 +574,15 @@ interruptOSThread (OSThreadId id) CloseHandle(hdl); } +void +joinOSThread (OSThreadId id) +{ + int ret = WaitForSingleObject(id, INFINITE); + if (ret != WAIT_OBJECT_0) { + sysErrorBelch("joinOSThread: error %d", ret); + } +} + void setThreadNode (uint32_t node) { if (osNumaAvailable()) |