Use thr_join(3T) to wait for a thread to terminate. (For POSIX threads, see "pthread_join(3T)".)
#include <thread.h> int thr_join(thread_t tid, thread_t *departedid, void **status);
#include <thread.h> thread_t tid; thread_t departedid; int ret; int status; /* waiting to join thread "tid" with status */ ret = thr_join(tid, &departedid, (void**)&status); /* waiting to join thread "tid" without status */ ret = thr_join(tid, &departedid, NULL); /* waiting to join thread "tid" without return id and status */ ret = thr_join(tid, NULL, NULL);
When the tid is (thread_t)0
, then thread_join() waits for any undetached thread in the process to terminate. In other words, when no thread identifier is specified, any undetached thread that exits causes thread_join() to return.
#include <thread.h> thread_t tid; thread_t departedid; int ret; int status; /* waiting to join thread "tid" with status */ ret = thr_join(NULL, &departedid, (void **)&status);
By indicating NULL as thread id in the Solaris thr_join(), a join will take place when any non detached thread in the process exits. The departedid will indicate the thread ID of exiting thread.