#include "pthread_impl.h" #include #include int thrd_detach(thrd_t t) { /* Cannot detach a thread that's already exiting */ if (a_swap(t->exitlock, 1)){ int tmp; while ((tmp = t->tid)) __timedwait(&t->tid, tmp, 0, 0, 0, 0, 0); if (t->map_base) munmap(t->map_base, t->map_size); } else { t->detached = 2; __unlock(t->exitlock); } return thrd_success; }