cc –mt [ flag... ] file...[ library... ] #include <thread.h>int thr_join(thread_t thread, thread_t *departed, void **status);
The thr_join() functions suspend processing of the calling thread until the target thread completes. thread must be a member of the current process and it cannot be a detached or daemon thread. See thr_create(3THR).
Several threads cannot wait for the same thread to complete; one thread will complete successfully and the others will terminate with an error of ESRCH. thr_join() will not block processing of the calling thread if the target thread has already terminated.
thr_join() returns successfully when the target thread terminates.
If a thr_join() call returns successfully with a non-null status argument, the value passed to thr_exit(3THR) by the terminating thread will be placed in the location referenced by status.
If the target thread ID is 0, thr_join() waits for any undetached thread in the process to terminate.
If departed is not NULL, it points to a location that is set to the ID of the terminated thread if thr_join() returns successfully.
If successful, thr_join() returns 0. Otherwise, an error number is returned to indicate the error.
No undetached thread could be found corresponding to that specified by the given thread ID.
A recursive deadlock was detected, the value of thread specifies the calling thread. See NOTES.
See attributes(5) for descriptions of the following attributes:
|ATTRIBUTE TYPE||ATTRIBUTE VALUE|
Using thr_join(3THR) in the following syntax,
while (thr_join(NULL, NULL, NULL) == 0);
will wait for the termination of all other undetached and non-daemon threads; after which, EDEADLK will be returned.SunOS 5.8 Last Revised 9 May 1998