mount_setattr.2: Further tweaks after feedback from Christian Brauner
[man-pages.git] / man3 / pthread_tryjoin_np.3
blobe2b142504f9536c8c7ae987d1df533ba1a56ee30
1 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2 .\"     <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .TH PTHREAD_TRYJOIN_NP 3 2021-03-22 "Linux" "Linux Programmer's Manual"
27 .SH NAME
28 pthread_tryjoin_np, pthread_timedjoin_np \- try to join with a
29 terminated thread
30 .SH SYNOPSIS
31 .nf
32 .BR "#define _GNU_SOURCE" "             /* See feature_test_macros(7) */"
33 .B #include <pthread.h>
34 .PP
35 .BI "int pthread_tryjoin_np(pthread_t " thread ", void **" retval );
36 .BI "int pthread_timedjoin_np(pthread_t " thread ", void **" retval ,
37 .BI "                         const struct timespec *" abstime );
38 .fi
39 .PP
40 Compile and link with \fI\-pthread\fP.
41 .SH DESCRIPTION
42 These functions operate in the same way as
43 .BR pthread_join (3),
44 except for the differences described on this page.
45 .PP
46 The
47 .BR pthread_tryjoin_np ()
48 function performs a nonblocking join with the thread
49 .IR thread ,
50 returning the exit status of the thread in
51 .IR *retval .
53 .I thread
54 has not yet terminated, then instead of blocking, as is done by
55 .BR pthread_join (3),
56 the call returns an error.
57 .PP
58 The
59 .BR pthread_timedjoin_np ()
60 function performs a join-with-timeout.
62 .I thread
63 has not yet terminated,
64 then the call blocks until a maximum time, specified in
65 .IR abstime ,
66 measured against the
67 .BR CLOCK_REALTIME
68 clock.
69 If the timeout expires before
70 .I thread
71 terminates,
72 the call returns an error.
73 The
74 .I abstime
75 argument is a structure of the following form,
76 specifying an absolute time measured since the Epoch (see
77 .BR time (2)):
78 .PP
79 .in +4n
80 .EX
81 struct timespec {
82     time_t tv_sec;     /* seconds */
83     long   tv_nsec;    /* nanoseconds */
85 .EE
86 .in
87 .SH RETURN VALUE
88 On success,
89 these functions return 0;
90 on error, they return an error number.
91 .SH ERRORS
92 These functions can fail with the same errors as
93 .BR pthread_join (3).
94 .BR pthread_tryjoin_np ()
95 can in addition fail with the following error:
96 .TP
97 .B EBUSY
98 .I thread
99 had not yet terminated at the time of the call.
101 .BR pthread_timedjoin_np ()
102 can in addition fail with the following errors:
104 .BR ETIMEDOUT
105 The call timed out before
106 .I thread
107 terminated.
109 .BR EINVAL
110 .I abstime
111 value is invalid
112 .RI ( tv_sec
113 is less than 0 or
114 .IR tv_nsec
115 is greater than 1e9).
117 .BR pthread_timedjoin_np ()
118 never returns the error
119 .BR EINTR .
120 .SH VERSIONS
121 These functions first appeared in glibc in version 2.3.3.
122 .SH ATTRIBUTES
123 For an explanation of the terms used in this section, see
124 .BR attributes (7).
125 .ad l
128 allbox;
129 lbx lb lb
130 l l l.
131 Interface       Attribute       Value
133 .BR pthread_tryjoin_np (),
134 .BR pthread_timedjoin_np ()
135 T}      Thread safety   MT-Safe
139 .sp 1
140 .SH CONFORMING TO
141 These functions are nonstandard GNU extensions;
142 hence the suffix "_np" (nonportable) in the names.
143 .SH EXAMPLES
144 The following code waits to join for up to 5 seconds:
146 .in +4n
148 struct timespec ts;
149 int s;
151 \&...
153 if (clock_gettime(CLOCK_REALTIME, &ts) == \-1) {
154     /* Handle error */
157 ts.tv_sec += 5;
159 s = pthread_timedjoin_np(thread, NULL, &ts);
160 if (s != 0) {
161     /* Handle error */
165 .SH BUGS
167 .BR pthread_timedjoin_np ()
168 function measures time by internally calculating a relative sleep interval
169 that is then measured against the
170 .BR CLOCK_MONOTONIC
171 clock instead of the
172 .BR CLOCK_REALTIME
173 clock.
174 Consequently, the timeout is unaffected by discontinuous changes to the
175 .BR CLOCK_REALTIME
176 clock.
177 .SH SEE ALSO
178 .BR clock_gettime (2),
179 .BR pthread_exit (3),
180 .BR pthread_join (3),
181 .BR pthreads (7)