It is impossible to join a detached thread, even if it is not yet terminated. The target thread is automatically detached after all joined threads have been woken up. This subroutine does not itself cause a thread to be terminated. In this case, the flag is automatically set. This storage shall be reclaimed on process exit, regardless of whether the thread has been detached or not, and may include storage for thread return value.
Parameters thread Specifies the target thread.
If the value is NULL , the termination status is not returned. Otherwise, an error number is returned to indicate the error. The implementation has detected that the value specified by thread does not refer to a joinable thread.