Once a thread is detached, it is automatically deleted after it terminates; that is, no explicit deletion operation is required. If the thread has not yet terminated, the pthread_detach routine marks the thread for deletion, and its storage is reclaimed immediately when the thread terminates. A thread cannot be joined or canceled after the phread_detach routine has been called for the thread (even if the thread has not yet terminated).
If a thread that has not been detached terminates, its storage is retained so that other threads can join with it. The storage is reclaimed when the thread is detached.