thr_join() 関数はスレッドの終了を待ちます。
#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; /* スレッド「tid」の終了待ち、status の指定あり */ ret = thr_join(tid, &departedid, (void**)&status); /* スレッド「tid」の終了待ち、status の指定なし */ ret = thr_join(tid, &departedid, NULL); /* スレッド「tid」の終了待ち、departedid と status の指定なし */ ret = thr_join(tid, NULL, NULL);
tid が (thread_t) 0
の場合は、thr_join() はプロセス内の切り離されていない任意のスレッドの終了を待ちます。つまり、スレッド識別子を指定しなければ、切り離されていないスレッドのどれかが終了すると thr_join() が復帰します。
#include <thread.h> thread_t tid; thread_t departedid; int ret; int status; /* スレッド「tid」の終了待ち、status の指定あり */ ret = thr_join(NULL, &departedid, (void **)&status);
thr_join() でスレッド識別子として NULL を指定すると、プロセス内の切り離されていない任意のスレッドの終了を待ちます。departedid には、終了したスレッドのスレッド識別子が格納されます。