A thread is automatically deleted after it terminates; that is, no explicit deletion operation is required. Use pthread_detach( ) to free the storage of a terminated thread. Use pthread_cancel( ) to request that a running thread terminate itself.
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 pthread_detach( ) routine is called for the thread, even if the thread has not yet terminated.
If a thread that is not detached terminates, its storage remains so that other threads can join with it. Storage is reclaimed when the thread is eventually detached.