pthread_detach(3T) is an alternative to pthread_join(3T)() to reclaim storage for a thread that is created with a detachstate attribute set to PTHREAD_CREATE_JOINABLE.
Prototype: int pthread_detach(thread_t tid);
#include <pthread.h> pthread_t tid; int ret; /* detach thread tid */ ret = pthread_detach(tid);
The pthread_detach() function is used to indicate to the implementation that storage for the thread tid can be reclaimed when the thread terminates. If tid has not terminated, pthread_detach() does not cause it to terminate. The effect of multiple pthread_detach() calls on the same target thread is unspecified.
pthread_detach() returns a zero when it completes successfully. Any other returned value indicates that an error occurred. When any of the following conditions are detected, pthread_detach() fails and returns the corresponding value.