path: root/src/internal/pthread_impl.h
diff options
authorRich Felker <>2018-05-05 21:33:58 -0400
committerRich Felker <>2018-05-05 21:33:58 -0400
commitcdba6b2562bc5c2078e0e1e6f86c8835a42ae4ff (patch)
treef452bf4d2f4275ae2945ef860826f6640e8fc830 /src/internal/pthread_impl.h
parent526e64f54d729947b35fd39129bc86cbc0b5f098 (diff)
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/internal/pthread_impl.h')
1 files changed, 9 insertions, 3 deletions
diff --git a/src/internal/pthread_impl.h b/src/internal/pthread_impl.h
index 3b4ad94d..0a65fa37 100644
--- a/src/internal/pthread_impl.h
+++ b/src/internal/pthread_impl.h
@@ -24,7 +24,7 @@ struct pthread {
/* Part 2 -- implementation details, non-ABI. */
int tsd_used, errno_val;
volatile int cancel, canceldisable, cancelasync;
- int detached;
+ volatile int detach_state;
unsigned char *map_base;
size_t map_size;
void *stack;
@@ -42,9 +42,7 @@ struct pthread {
int unblock_cancel;
volatile int timer_id;
locale_t locale;
- volatile int join_futex;
volatile int killlock[1];
- volatile int exitlock[1];
volatile int startlock[2];
unsigned long sigmask[_NSIG/8/sizeof(long)];
char *dlerror_buf;
@@ -58,6 +56,14 @@ struct pthread {
void **dtv_copy;
+enum {
+ DT_EXITED = 0,
struct __timer {
int timerid;
pthread_t thread;