#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <pthread.h>
int pthread_tryjoin_np(pthread_t thread, void **retval);
int pthread_timedjoin_np(pthread_t thread, void **retval,
const struct timespec *abstime);
pthread_tryjoin_np() 関数は、スレッド thread の非停止 (nonblocking) での join を実行し、スレッドの終了ステータスを *retval に入れて返す。thread がまだ終了していない場合は、 pthread_join(3) のように停止 (block) せずに、エラーを返す。
The pthread_timedjoin_np() function performs a join-with-timeout. If thread has not yet terminated, then the call blocks until a maximum time, specified in abstime, measured against the CLOCK_REALTIME clock. If the timeout expires before thread terminates, the call returns an error. The abstime argument is a structure of the following form, specifying an absolute time measured since the Epoch (see time(2)):
struct timespec {
time_t tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */
};
pthread_timedjoin_np() はさらに以下のエラーで失敗する場合がある。
pthread_timedjoin_np() がエラー EINTR を返すことはない。
| インターフェース | 属性 | 値 |
| pthread_tryjoin_np(), pthread_timedjoin_np() | Thread safety | MT-Safe |
struct timespec ts; int s;
...
if (clock_gettime(CLOCK_REALTIME, &ts) == -1) {
/* Handle error */
}
ts.tv_sec += 5;
s = pthread_timedjoin_np(thread, NULL, &ts);
if (s != 0) {
/* Handle error */
}