lk/kernel/thread.c
status_t thread_detach(thread_t *t) { DEBUG_ASSERT(t->magic == THREAD_MAGIC);
THREAD_LOCK(state);
/* if another thread is blocked inside thread_join() on this thread, * wake them up with a specific return code */ wait_queue_wake_all(&t->retcode_wait_queue, false, ERR_THREAD_DETACHED);
/* if it's already dead, then just do what join would have and exit */ if (t->state == THREAD_DEATH) { t->flags &= ~THREAD_FLAG_DETACHED; /* makes sure thread_join continues */ THREAD_UNLOCK(state); return thread_join(t, NULL, 0); } else { t->flags |= THREAD_FLAG_DETACHED; THREAD_UNLOCK(state); return NO_ERROR; } }