summaryrefslogtreecommitdiff
path: root/src/env
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2018-05-05 21:33:58 -0400
committerRich Felker <dalias@aerifal.cx>2018-05-05 21:33:58 -0400
commitcdba6b2562bc5c2078e0e1e6f86c8835a42ae4ff (patch)
treef452bf4d2f4275ae2945ef860826f6640e8fc830 /src/env
parent526e64f54d729947b35fd39129bc86cbc0b5f098 (diff)
downloadmusl-cdba6b2562bc5c2078e0e1e6f86c8835a42ae4ff.tar.gz
musl-cdba6b2562bc5c2078e0e1e6f86c8835a42ae4ff.tar.bz2
musl-cdba6b2562bc5c2078e0e1e6f86c8835a42ae4ff.tar.xz
musl-cdba6b2562bc5c2078e0e1e6f86c8835a42ae4ff.zip
improve joinable/detached thread state handling
previously, some accesses to the detached state (from pthread_join and pthread_getattr_np) were unsynchronized; they were harmless in programs with well-defined behavior, but ugly. other accesses (in pthread_exit and pthread_detach) were synchronized by a poorly named "exitlock", with an ad-hoc trylock operation on it open-coded in pthread_detach, whose only purpose was establishing protocol for which thread is responsible for deallocation of detached-thread resources. instead, use an atomic detach_state and unify it with the futex used to wait for thread exit. this eliminates 2 members from the pthread structure, gets rid of the hackish lock usage, and makes rigorous the trap added in commit 80bf5952551c002cf12d96deb145629765272db0 for catching attempts to join detached threads. it should also make attempt to detach an already-detached thread reliably trap.
Diffstat (limited to 'src/env')
-rw-r--r--src/env/__init_tls.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/env/__init_tls.c b/src/env/__init_tls.c
index 80044960..1c5d98a0 100644
--- a/src/env/__init_tls.c
+++ b/src/env/__init_tls.c
@@ -15,8 +15,8 @@ int __init_tp(void *p)
int r = __set_thread_area(TP_ADJ(p));
if (r < 0) return -1;
if (!r) libc.can_do_threads = 1;
- td->join_futex = -1;
- td->tid = __syscall(SYS_set_tid_address, &td->join_futex);
+ td->detach_state = DT_JOINABLE;
+ td->tid = __syscall(SYS_set_tid_address, &td->detach_state);
td->locale = &libc.global_locale;
td->robust_list.head = &td->robust_list.head;
return 0;