summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2020-03-10 22:55:19 -0400
committerBen Gamari <ben@well-typed.com>2020-12-01 12:48:54 -0500
commitf9480f502a09e8d727ae90b0614a67fd2d4ee2dd (patch)
tree3e7c995f189eacb196732a1ab3dda8f74addd5de
parent84cf7ed6cde69b8e677c465628647ac902bbc23f (diff)
downloadhaskell-f9480f502a09e8d727ae90b0614a67fd2d4ee2dd.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.h3
-rw-r--r--rts/posix/OSThreads.c8
-rw-r--r--rts/sm/NonMoving.c1
-rw-r--r--rts/win32/OSThreads.c9
4 files changed, 20 insertions, 1 deletions
diff --git a/includes/rts/OSThreads.h b/includes/rts/OSThreads.h
index 322624e8ad..c99a269a08 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 b34c292dd8..e5cf9e6d6a 100644
--- a/rts/posix/OSThreads.c
+++ b/rts/posix/OSThreads.c
@@ -377,6 +377,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/sm/NonMoving.c b/rts/sm/NonMoving.c
index 4519a33314..538583e687 100644
--- a/rts/sm/NonMoving.c
+++ b/rts/sm/NonMoving.c
@@ -726,6 +726,7 @@ void nonmovingStop(void)
"waiting for nonmoving collector thread to terminate");
ACQUIRE_LOCK(&concurrent_coll_finished_lock);
waitCondition(&concurrent_coll_finished, &concurrent_coll_finished_lock);
+ joinOSThread(mark_thread);
}
#endif
}
diff --git a/rts/win32/OSThreads.c b/rts/win32/OSThreads.c
index 0942382da2..0ef2a7e293 100644
--- a/rts/win32/OSThreads.c
+++ b/rts/win32/OSThreads.c
@@ -582,6 +582,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())