PTHREAD_TRYJOIN_NP

Section: Linux Programmer's Manual (3)
Updated: 2020-12-21
Index JM Home Page
 

名前

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

書式

#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 を付けてコンパイルとリンクを行う。  

説明

これらの関数は 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 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 */ };  

返り値

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

エラー

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

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

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

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

バージョン

これらの関数は glibc バージョン 2.3.3 で初めて登場した。  

属性

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

準拠

これらの関数は非標準の GNU による拡張である。 そのため、名前に "_np" (nonportable; 移植性がない) という接尾辞が 付いている。  

例

以下のコードは、最大 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 */ }  

バグ

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.  

関連項目

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

この文書について

この man ページは Linux man-pages プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は https://www.kernel.org/doc/man-pages/ に書かれている。

関連キーワード

pthread   timedjoin   join   tryjoin   clock   time   スレッド   struct   timespec   measured   停止   call   against   timeout   nsec   gettime   Handle   define   feature   macros   コンパイル   nonblocking   ステータス   retval   block

Linux マニュアル 一覧

関連するコマンド・関数

pthread_timedjoin_np.3   pthread_join.3   join.1   pthread_detach.3   pthread_attr_getdetachstate.3   pthread_attr_setdetachstate.3
 

Index

名前
書式
説明
返り値
エラー
バージョン
属性
準拠
例
バグ
関連項目
この文書について

This document was created by man2html, using the manual pages.
Time: 04:39:37 GMT, October 11, 2026