Blocks or detaches the calling thread until the specified thread terminates.
Threads Library (libpthreads.a)
#include <pthread.h> int pthread_join (thread, status) pthread_t thread; void **status; int pthread_detach (thread) pthread_t thread;
The pthread_join subroutine blocks the calling thread until the thread thread terminates. The target thread's termination status is returned in the status parameter.
If the target thread is already terminated, but not yet detached, the subroutine returns immediately. 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. It acts like the pthread_cond_wait subroutine to wait for a special condition.
The pthread_detach subroutine is used to indicate to the implementation that storage for the thread whose thread ID is in the location thread can be reclaimed when that thread terminates. 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. If thread has not yet terminated, pthread_detach shall not cause it to terminate. Multiple pthread_detach calls on the same target thread causes an error.
thread | Specifies the target thread. |
status | Points to where the termination status of the target thread will be stored. If the value is NULL, the termination status is not returned. |
If successful, the pthread_join function returns zero. Otherwise, an error number is returned to indicate the error.
The pthread_join and pthread_detach functions will fail if:
EINVAL | The implementation has detected that the value specified by thread does not refer to a joinable thread. |
ESRCH | No thread could be found corresponding to that specified by the given thread ID. |
The pthread_join function will fail if:
EDEADLK | The value of thread specifies the calling thread. |
The pthread_join function will not return an error code of EINTR.
The pthread_exit (pthread_exit Subroutine) subroutine, pthread_create (pthread_create Subroutine) subroutine, wait subroutine, pthread_cond_wait or pthread_cond_timedwait (pthread_cond_wait or pthread_cond_timedwait Subroutine) subroutines, the pthread.h file.
Joining Threads in AIX 5L Version 5.2 General Programming Concepts: Writing and Debugging Programs.
Threads Library Quick Reference in AIX 5L Version 5.2 General Programming Concepts: Writing and Debugging Programs.