]>
Commit | Line | Data |
---|---|---|
681f0d67 MK |
1 | .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk |
2 | .\" <mtk.manpages@gmail.com> | |
3 | .\" | |
5fbde956 | 4 | .\" SPDX-License-Identifier: Linux-man-pages-copyleft |
681f0d67 | 5 | .\" |
6e00b7a8 | 6 | .TH PTHREAD_TRYJOIN_NP 3 2021-08-27 "Linux" "Linux Programmer's Manual" |
681f0d67 MK |
7 | .SH NAME |
8 | pthread_tryjoin_np, pthread_timedjoin_np \- try to join with a | |
9 | terminated thread | |
4b76034e AC |
10 | .SH LIBRARY |
11 | POSIX threads library | |
8fc3b2cf | 12 | .RI ( libpthread ", " \-lpthread ) |
681f0d67 MK |
13 | .SH SYNOPSIS |
14 | .nf | |
86b91fdf | 15 | .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */" |
681f0d67 | 16 | .B #include <pthread.h> |
dbfe9c70 | 17 | .PP |
681f0d67 | 18 | .BI "int pthread_tryjoin_np(pthread_t " thread ", void **" retval ); |
681f0d67 | 19 | .BI "int pthread_timedjoin_np(pthread_t " thread ", void **" retval , |
5b4e617f | 20 | .BI " const struct timespec *" abstime ); |
681f0d67 | 21 | .fi |
681f0d67 MK |
22 | .SH DESCRIPTION |
23 | These functions operate in the same way as | |
24 | .BR pthread_join (3), | |
25 | except for the differences described on this page. | |
847e0d88 | 26 | .PP |
681f0d67 MK |
27 | The |
28 | .BR pthread_tryjoin_np () | |
ff40dbb3 | 29 | function performs a nonblocking join with the thread |
681f0d67 MK |
30 | .IR thread , |
31 | returning the exit status of the thread in | |
32 | .IR *retval . | |
33 | If | |
34 | .I thread | |
35 | has not yet terminated, then instead of blocking, as is done by | |
36 | .BR pthread_join (3), | |
37 | the call returns an error. | |
847e0d88 | 38 | .PP |
681f0d67 MK |
39 | The |
40 | .BR pthread_timedjoin_np () | |
41 | function performs a join-with-timeout. | |
42 | If | |
43 | .I thread | |
44 | has not yet terminated, | |
45 | then the call blocks until a maximum time, specified in | |
6c9fd46b MK |
46 | .IR abstime , |
47 | measured against the | |
1ae6b2c7 | 48 | .B CLOCK_REALTIME |
6c9fd46b | 49 | clock. |
681f0d67 MK |
50 | If the timeout expires before |
51 | .I thread | |
52 | terminates, | |
53 | the call returns an error. | |
54 | The | |
55 | .I abstime | |
e97e048a | 56 | argument is a |
57 | .BR timespec (3) | |
58 | structure, | |
681f0d67 | 59 | specifying an absolute time measured since the Epoch (see |
e97e048a | 60 | .BR time (2)). |
681f0d67 MK |
61 | .SH RETURN VALUE |
62 | On success, | |
63 | these functions return 0; | |
64 | on error, they return an error number. | |
65 | .SH ERRORS | |
66 | These functions can fail with the same errors as | |
67 | .BR pthread_join (3). | |
68 | .BR pthread_tryjoin_np () | |
69 | can in addition fail with the following error: | |
70 | .TP | |
71 | .B EBUSY | |
72 | .I thread | |
73 | had not yet terminated at the time of the call. | |
74 | .PP | |
75 | .BR pthread_timedjoin_np () | |
dc891cf9 | 76 | can in addition fail with the following errors: |
681f0d67 | 77 | .TP |
1ae6b2c7 | 78 | .B EINVAL |
e7e39a14 | 79 | .I abstime |
305965f5 MK |
80 | value is invalid |
81 | .RI ( tv_sec | |
82 | is less than 0 or | |
1ae6b2c7 | 83 | .I tv_nsec |
305965f5 | 84 | is greater than 1e9). |
97e2d8e6 | 85 | .TP |
1ae6b2c7 | 86 | .B ETIMEDOUT |
97e2d8e6 MK |
87 | The call timed out before |
88 | .I thread | |
89 | terminated. | |
681f0d67 MK |
90 | .PP |
91 | .BR pthread_timedjoin_np () | |
92 | never returns the error | |
93 | .BR EINTR . | |
94 | .SH VERSIONS | |
95 | These functions first appeared in glibc in version 2.3.3. | |
672a9903 ZL |
96 | .SH ATTRIBUTES |
97 | For an explanation of the terms used in this section, see | |
98 | .BR attributes (7). | |
74714ea8 | 99 | .ad l |
c466875e | 100 | .nh |
672a9903 ZL |
101 | .TS |
102 | allbox; | |
c466875e | 103 | lbx lb lb |
672a9903 ZL |
104 | l l l. |
105 | Interface Attribute Value | |
106 | T{ | |
107 | .BR pthread_tryjoin_np (), | |
108 | .BR pthread_timedjoin_np () | |
109 | T} Thread safety MT-Safe | |
110 | .TE | |
c466875e | 111 | .hy |
74714ea8 | 112 | .ad |
c466875e | 113 | .sp 1 |
681f0d67 | 114 | .SH CONFORMING TO |
c8f2dd47 | 115 | These functions are nonstandard GNU extensions; |
d603cc27 | 116 | hence the suffix "_np" (nonportable) in the names. |
dae872dd MK |
117 | .SH BUGS |
118 | The | |
119 | .BR pthread_timedjoin_np () | |
120 | function measures time by internally calculating a relative sleep interval | |
121 | that is then measured against the | |
1ae6b2c7 | 122 | .B CLOCK_MONOTONIC |
dae872dd | 123 | clock instead of the |
1ae6b2c7 | 124 | .B CLOCK_REALTIME |
dae872dd MK |
125 | clock. |
126 | Consequently, the timeout is unaffected by discontinuous changes to the | |
1ae6b2c7 | 127 | .B CLOCK_REALTIME |
dae872dd | 128 | clock. |
a14af333 | 129 | .SH EXAMPLES |
681f0d67 | 130 | The following code waits to join for up to 5 seconds: |
847e0d88 | 131 | .PP |
207050fa MK |
132 | .in +4n |
133 | .EX | |
134 | struct timespec ts; | |
135 | int s; | |
681f0d67 | 136 | |
207050fa | 137 | \&... |
681f0d67 | 138 | |
207050fa MK |
139 | if (clock_gettime(CLOCK_REALTIME, &ts) == \-1) { |
140 | /* Handle error */ | |
141 | } | |
681f0d67 | 142 | |
207050fa | 143 | ts.tv_sec += 5; |
681f0d67 | 144 | |
207050fa MK |
145 | s = pthread_timedjoin_np(thread, NULL, &ts); |
146 | if (s != 0) { | |
147 | /* Handle error */ | |
148 | } | |
b9c93deb | 149 | .EE |
207050fa | 150 | .in |
681f0d67 | 151 | .SH SEE ALSO |
0eb44391 | 152 | .BR clock_gettime (2), |
681f0d67 | 153 | .BR pthread_exit (3), |
3e5c319e | 154 | .BR pthread_join (3), |
e97e048a | 155 | .BR timespec (3), |
681f0d67 | 156 | .BR pthreads (7) |