Error in "test thread-5.2": joined detached thread does not always return error
Closed / Fixed5974ff814c697f0118bc739d35c88205b06f5e92Created 11 years agoUpdated 45 days ago
Descriptionplain2015-09-21 09:12:58
The test 5.2 in thread.test makes the assumption that joining a detached thread will return an error. As per the POSIX spec, calling pthread_join on a detached thread is undefined behavior. Currently, this test never finishes on musl libc.
Referenced by1
e39d1f0e98Fix [5974ff814c]: on Unix, Tcl_JoinThread() called pthread_join() for detached threads, which is undefined behavior (hangs on musl, "succeeds" on glibc for an exited thread). Keep the list of joinable threads, and join only those, only once. Tests thread-5.3 to thread-5.5. check-in2026-10-14 19:45:27
oehhar Ticket [5974ff814c]: 3 changes
[History diff]2015-09-23 13:42:08
anonymousplain2018-11-18 18:15:08
Still the case in version 8.6.9
serhiy.storchakawiki2026-10-14 19:49:47
This is a bug in Tcl, not only in the test: on Unix Tcl_JoinThread() calls pthread_join() for any thread, also a detached one. With glibc, joining a detached thread that has already exited even "succeeds" (reproduced with 8.6.18, 9.0.5 and 9.1 using [testthread]).
Proposed fix in branch unix-join-detached-thread: Tcl_JoinThread() only joins threads created joinable, and only once, as on Windows. Tests thread-5.3 to thread-5.5.
jan.nijtmanswiki2026-10-18 21:50:45
Fixed in [trunk], core-9-0-branch and core-8-6-branch
Many thanks!
Log in (anonymous is fine) to add a comment.