improve joinable/detached thread state handling
authorRich Felker <dalias@aerifal.cx>
Sun, 6 May 2018 01:33:58 +0000 (21:33 -0400)
committerRich Felker <dalias@aerifal.cx>
Sun, 6 May 2018 01:33:58 +0000 (21:33 -0400)
commitcdba6b2562bc5c2078e0e1e6f86c8835a42ae4ff
treef452bf4d2f4275ae2945ef860826f6640e8fc830
parent526e64f54d729947b35fd39129bc86cbc0b5f098
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.
src/env/__init_tls.c
src/internal/pthread_impl.h
src/thread/pthread_create.c
src/thread/pthread_detach.c
src/thread/pthread_getattr_np.c
src/thread/pthread_join.c