fix potential race condition in detached threads
[musl] / src / thread / pthread_detach.c
1 #include "pthread_impl.h"
2
3 int pthread_detach(pthread_t t)
4 {
5         /* Cannot detach a thread that's already exiting */
6         if (a_swap(&t->exitlock, 1))
7                 return pthread_join(t, 0);
8         t->detached = 2;
9         a_store(&t->exitlock, 0);
10         return 0;
11 }