This routine marks the specified thread object to indicate that
storage for the corresponding thread can be reclaimed when
the thread terminates. This includes storage for the thread
argument's return value, as well as the thread object. If thread
has not terminated when this routine is called, this routine does
not cause it to terminate.
When a thread object is no longer referenced, call this routine.
The results of this routine are unpredictable if the value of
thread refers to a thread object that does not exist.
You can create a thread already detached by setting its thread
object's detachstate attribute.
The pthread_join() routine also detaches the target thread after
pthread_join() returns successfully.