summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rts/include/rts/OSThreads.h4
-rw-r--r--rts/posix/OSThreads.c19
-rw-r--r--rts/posix/ticker/Pthread.c23
3 files changed, 20 insertions, 26 deletions
diff --git a/rts/include/rts/OSThreads.h b/rts/include/rts/OSThreads.h
index 563e886469..ebe964be9a 100644
--- a/rts/include/rts/OSThreads.h
+++ b/rts/include/rts/OSThreads.h
@@ -175,6 +175,10 @@ typedef void* OSThreadProcAttr OSThreadProc(void *);
extern int createOSThread ( OSThreadId* tid, const char *name,
OSThreadProc *startProc, void *param);
+#if !defined(mingw32_HOST_OS)
+extern int createAttachedOSThread( OSThreadId *tid, const char *name,
+ OSThreadProc *startProc, void *param);
+#endif
extern bool osThreadIsAlive ( OSThreadId id );
extern void interruptOSThread ( OSThreadId id );
extern void joinOSThread ( OSThreadId id );
diff --git a/rts/posix/OSThreads.c b/rts/posix/OSThreads.c
index 2987e8162b..2784afe863 100644
--- a/rts/posix/OSThreads.c
+++ b/rts/posix/OSThreads.c
@@ -222,16 +222,25 @@ int
createOSThread (OSThreadId* pId, const char *name,
OSThreadProc *startProc, void *param)
{
- struct ThreadDesc *desc = stgMallocBytes(sizeof(struct ThreadDesc), "createOSThread");
+ int result = createAttachedOSThread(pId, name, startProc, param);
+ if (!result) {
+ pthread_detach(*pId);
+ }
+ return result;
+}
+
+int
+createAttachedOSThread (OSThreadId *pId, const char *name,
+ OSThreadProc *startProc, void *param)
+{
+ struct ThreadDesc *desc = stgMallocBytes(sizeof(struct ThreadDesc), "createAttachedOSThread");
desc->startProc = startProc;
desc->param = param;
- desc->name = stgMallocBytes(strlen(name) + 1, "createOSThread");
+ desc->name = stgMallocBytes(strlen(name) + 1, "createAttachedOSThread");
strcpy(desc->name, name);
int result = pthread_create(pId, NULL, start_thread, desc);
- if (!result) {
- pthread_detach(*pId);
- } else {
+ if (result) {
stgFree(desc->name);
stgFree(desc);
}
diff --git a/rts/posix/ticker/Pthread.c b/rts/posix/ticker/Pthread.c
index 01b3a5f901..a4c7af588f 100644
--- a/rts/posix/ticker/Pthread.c
+++ b/rts/posix/ticker/Pthread.c
@@ -188,15 +188,6 @@ initTicker (Time interval, TickProc handle_tick)
#endif
/*
- * We can't use the RTS's createOSThread here as we need to remain attached
- * to the thread we create so we can later join to it if requested
- *
- * On FreeBSD 12.2 pthread_set_name_np() is unconditionally declared in
- * <pthread_np.h>, while pthread_setname_np() is conditionally declared in
- * <pthread.h> when _POSIX_SOURCE is not defined, but we're including
- * <rts/PosixSource.h>, so must use pthread_set_name_np() instead. See
- * similar code in "rts/posix/OSThreads.c".
- *
* Create the thread with all blockable signals blocked, leaving signal
* handling to the main and/or other threads. This is especially useful in
* the non-threaded runtime, where applications might expect sigprocmask(2)
@@ -206,23 +197,13 @@ initTicker (Time interval, TickProc handle_tick)
sigfillset(&mask);
sigret = pthread_sigmask(SIG_SETMASK, &mask, &omask);
#endif
- ret = pthread_create(&thread, NULL, itimer_thread_func, (void*)handle_tick);
+ ret = createAttachedOSThread(&thread, "ghc_ticker", itimer_thread_func, (void*)handle_tick);
#if defined(HAVE_SIGNAL_H)
if (sigret == 0)
pthread_sigmask(SIG_SETMASK, &omask, NULL);
#endif
- if (ret == 0) {
-#if defined(HAVE_PTHREAD_SET_NAME_NP)
- pthread_set_name_np(thread, "ghc_ticker");
-#elif defined(HAVE_PTHREAD_SETNAME_NP)
- pthread_setname_np(thread, "ghc_ticker");
-#elif defined(HAVE_PTHREAD_SETNAME_NP_DARWIN)
- pthread_setname_np("ghc_ticker");
-#elif defined(HAVE_PTHREAD_SETNAME_NP_NETBSD)
- pthread_setname_np(thread, "%s", "ghc_ticker");
-#endif
- } else {
+ if (ret != 0) {
barf("Ticker: Failed to spawn thread: %s", strerror(errno));
}
}