diff options
author | Nicolas Trangez <ikke@nicolast.be> | 2023-01-04 17:10:41 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2023-01-09 21:11:03 -0500 |
commit | cfaf1ad7d4f75fc3f04090a17cc675d0e54e8e55 (patch) | |
tree | 0939ab2b5113a40f54e97cb645db58082e54cb39 | |
parent | d53f6f4d98aabd6f5b28fb110db1da0f6db70a06 (diff) | |
download | haskell-cfaf1ad7d4f75fc3f04090a17cc675d0e54e8e55.tar.gz |
rts, tests: limit thread name length to 15 bytes
On Linux, `pthread_setname_np` (or rather, the kernel) only allows for
thread names up to 16 bytes, including the terminating null byte.
This commit adds a note pointing this out in `createOSThread`, and fixes
up two instances where a thread name of more than 15 characters long was
used (in the RTS, and in a test-case).
Fixes: #22366
Fixes: https://gitlab.haskell.org/ghc/ghc/-/issues/22366
See: https://gitlab.haskell.org/ghc/ghc/-/issues/22366#note_460796
-rw-r--r-- | rts/posix/OSThreads.c | 6 | ||||
-rw-r--r-- | rts/sm/NonMoving.c | 2 | ||||
-rw-r--r-- | testsuite/tests/rts/pause-resume/pause_resume.c | 2 |
3 files changed, 8 insertions, 2 deletions
diff --git a/rts/posix/OSThreads.c b/rts/posix/OSThreads.c index 44cda2626d..6e5c5999db 100644 --- a/rts/posix/OSThreads.c +++ b/rts/posix/OSThreads.c @@ -218,6 +218,12 @@ start_thread (void *param) return startProc(startParam); } +/* Note: at least on Linux/Glibc, `pthread_setname_np` restricts the name of + * a thread to 16 bytes, including the terminating null byte. Hence, make sure + * to only pass in names of up to 15 characters. Otherwise, + * `pthread_setname_np` when called in `start_thread` will fail with `ERANGE`, + * which is not checked for, and the thread won't be named at all. + */ int createOSThread (OSThreadId* pId, const char *name, OSThreadProc *startProc, void *param) diff --git a/rts/sm/NonMoving.c b/rts/sm/NonMoving.c index 2697c5d2aa..3731aebb95 100644 --- a/rts/sm/NonMoving.c +++ b/rts/sm/NonMoving.c @@ -1015,7 +1015,7 @@ void nonmovingCollect(StgWeak **dead_weaks, StgTSO **resurrected_threads) nonmoving_write_barrier_enabled = true; debugTrace(DEBUG_nonmoving_gc, "Starting concurrent mark thread"); OSThreadId thread; - if (createOSThread(&thread, "non-moving mark thread", + if (createOSThread(&thread, "nonmoving-mark", nonmovingConcurrentMark, mark_queue) != 0) { barf("nonmovingCollect: failed to spawn mark thread: %s", strerror(errno)); } diff --git a/testsuite/tests/rts/pause-resume/pause_resume.c b/testsuite/tests/rts/pause-resume/pause_resume.c index 213adf726c..969c5b1481 100644 --- a/testsuite/tests/rts/pause-resume/pause_resume.c +++ b/testsuite/tests/rts/pause-resume/pause_resume.c @@ -187,7 +187,7 @@ void pauseAndResumeViaThread ) { OSThreadId threadId; - createOSThread(&threadId, "Pause and resume thread", &pauseAndResumeViaThread_helper, (void *)count); + createOSThread(&threadId, "pause-resume", &pauseAndResumeViaThread_helper, (void *)count); } const int TIMEOUT = 1000000; // 1 second |