pthread_tryjoin_np

Section: C Library Functions (3)
Updated: 2025-05-17
Index JM Home Page roff page
 

名前

pthread_tryjoin_np, pthread_timedjoin_np - 終了したスレッドの join を 試みる  

ライブラリ

POSIX スレッドライブラリ (libpthread,~-lpthread)  

書式

#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_join(3) と同じように動作するが、 このページで説明する違いがある。

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 timespec(3) structure, specifying an absolute time measured since the Epoch (see time(2)).  

返り値

成功すると、これらの関数は 0 を返す。 エラーの場合、エラー番号を返す。  

エラー

これらの関数は pthread_join(3) と同じエラーで失敗する。 pthread_tryjoin_np() はさらに以下のエラーで失敗する場合がある。
EBUSY
呼び出しを行った時点では thread はまだ終了していない。

pthread_timedjoin_np() はさらに以下のエラーで失敗する場合がある。

EINVAL
abstime の値が無効である (tv_sec が 0 より小さいか、 tv_nsec 1e9 がより大きい)。
ETIMEDOUT
thread が終了する前に呼び出しがタイムアウトとなった。

pthread_timedjoin_np() がエラー EINTR を返すことはない。  

属性

この節で使用されている用語の説明については、 attributes(7) を参照。
インターフェース属性値
pthread_tryjoin_np(), pthread_timedjoin_np() Thread safetyMT-Safe
 

標準規格

GNU; そのため、名前に "_np" (nonportable; 移植性がない) という接尾辞が付いている。  

歴史

glibc 2.3.3.  

バグ

The pthread_timedjoin_np() function measures time by internally calculating a relative sleep interval that is then measured against the CLOCK_MONOTONIC clock instead of the CLOCK_REALTIME clock. Consequently, the timeout is unaffected by discontinuous changes to the CLOCK_REALTIME clock.  

例

以下のコードは、最大 5 秒まで join を待つ。

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 */
}
 

関連項目

clock_gettime(2), pthread_exit(3), pthread_join(3), timespec(3), pthreads(7)


 

Index

名前
ライブラリ
書式
説明
返り値
エラー
属性
標準規格
歴史
バグ
例
関連項目

This document was created by man2html, using the manual pages.