PTHREAD_TRYJOIN_NP - Linux手册页

Linux程序员手册 第3部分
更新日期: 2020-06-09

错误说明

这些函数可能会失败,并出现与pthread_join(3)相同的错误。另外,pthread_tryjoin_np()可能因以下错误而失败:

EBUSY
调用时线程尚未终止。

另外,pthread_timedjoin_np()可能因以下错误而失败:

ETIMEDOUT
该调用在线程终止之前超时。
EINVAL
abstime值无效(tv_sec小于0或tv_nsec大于1e9)。

pthread_timedjoin_np()从不返回错误EINTR。

另外参见

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

出版信息

这个页面是Linux手册页项目5.08版的一部分。有关项目的说明、有关报告错误的信息以及此页面的最新版本,请访问https://www.kernel.org/doc/man-pages/

名称

pthread_tryjoin_np,pthread_timedjoin_np-尝试与终止的线程连接

示例

以下代码等待加入最多5秒钟:

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

说明

这些功能与pthread_join(3)的操作方式相同,不同之处在于此页上所述的区别。

pthread_tryjoin_np()函数与线程线程执行非阻塞连接,并在* retval中返回线程的退出状态。如果线程尚未终止,则调用将返回错误,而不是像pthread_join(3)那样阻塞。

pthread_timedjoin_np()函数执行超时联接。如果线程尚未终止,则调用将阻塞直到abstime中指定的最大时间。如果超时在线程终止之前到期,则调用将返回错误。 abstime参数是以下形式的结构,用于指定自大纪元以来测量的绝对时间(请参见time(2)):

struct timespec {
    time_t tv_sec;     /* seconds */
    long   tv_nsec;    /* nanoseconds */
};

遵循规范

这些功能是非标准的GNU扩展。因此名称中的后缀" _np"(不可移植)。

属性

有关本节中使用的术语的说明,请参见attribute(7)。

InterfaceAttributeValue
pthread_tryjoin_np(),pthread_timedjoin_np()Thread safetyMT-Safe

返回值

成功时,这些函数返回0;否则,返回0。错误时,它们返回错误号。

语法

#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。

版本

这些功能首先出现在版本2.3.3的glibc中。

日期:2019-08-20 18:01:06 来源:oir作者:oir