diff options
Diffstat (limited to 'src/thread/pthread_detach.c')
-rw-r--r-- | src/thread/pthread_detach.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/thread/pthread_detach.c b/src/thread/pthread_detach.c index 692bbaf9..9cee7a89 100644 --- a/src/thread/pthread_detach.c +++ b/src/thread/pthread_detach.c @@ -5,11 +5,10 @@ int __pthread_join(pthread_t, void **); static int __pthread_detach(pthread_t t) { - /* Cannot detach a thread that's already exiting */ - if (a_cas(t->exitlock, 0, INT_MIN + 1)) + /* If the cas fails, detach state is either already-detached + * or exiting/exited, and pthread_join will trap or cleanup. */ + if (a_cas(&t->detach_state, DT_JOINABLE, DT_DYNAMIC) != DT_JOINABLE) return __pthread_join(t, 0); - t->detached = 2; - UNLOCK(t->exitlock); return 0; } |