Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2026-10-18
21:50 • Closed ticket [5974ff814c]: Error in "test thread-5.2": joined detache... artifact: 4f1b6898bd user: jan.nijtmans
21:49
Fix [5974ff]: on Unix, Tcl_JoinThread() should not call pthread_join() for detached threads check-in: 8a865640f8 user: jan.nijtmans tags: core-8-6-branch
2026-10-16
13:51
Fix [5974ff]: on Unix, Tcl_JoinThread() should not call pthread_join() for detached threads check-in: 8b196a3023 user: jan.nijtmans tags: core-9-0-branch
13:46
Fix [5974ff]: on Unix, Tcl_JoinThread() should not call pthread_join() for detached threads check-in: 30d8ccce48 user: jan.nijtmans tags: trunk, main
2026-10-14
19:49 • Ticket [5974ff814c] Error in "test thread-5.2": joined detached thread... artifact: f32644fc02 user: serhiy.storchaka
19:45
Fix [5974ff814c]: on Unix, Tcl_JoinThread() called pthread_join() for detached threads, which is und... closed check-in: e39d1f0e98 user: serhiy.storchaka tags: unix-join-detached-thread
2018-11-18
18:15 • Ticket [5974ff814c] Error in "test thread-5.2": joined detached thread... artifact: 913a6f738f user: anonymous
2015-09-23
13:42 • Ticket [5974ff814c]: 3 changes artifact: 37416b13fa user: oehhar
2015-09-21
09:12 • New ticket [5974ff814c]. artifact: 52ed726de5 user: anonymous

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.