A thread exists until it terminates and the thread has been detached. If the thread terminates before it is detached, then the thread continues to exist and other threads can join with it. Threads can be created in detached state, threads can be detached by calling pthread_detach, and are automatically detached when pthread_ join returns.
A thread terminates for any of the following reasons:
The pthread_exit routine terminates the calling thread and returns a status value (value_ptr argument) to indicate the thread's exit status to any thread that calls pthread_join.
The pthread_cancel routine requests termination of a specified thread if cancellation is permitted. See Section 2.6 for more information on canceling threads and controlling whether or not cancellation is permitted.