pthread_join() returns zero when the call completes successfully. Any other return value indicates that an error occurred. When any of the following conditions are detected, pthread_join() fails and returns the corresponding value.
No thread could be found corresponding to the given thread ID.
A deadlock would exist, such as a thread waits for itself or thread A waits for thread B and thread B waits for thread A.
The thread corresponding to the given thread ID is a detached thread.
pthread_join() works only for target threads that are nondetached. When no reason exists to synchronize with the termination of a particular thread, then that thread should be detached.