1 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
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.
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.
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
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
26 .TH PTHREAD_JOIN 3 2021-03-22 "Linux" "Linux Programmer's Manual"
28 pthread_join \- join with a terminated thread
31 .B #include <pthread.h>
33 .BI "int pthread_join(pthread_t " thread ", void **" retval );
36 Compile and link with \fI\-pthread\fP.
40 function waits for the thread specified by
43 If that thread has already terminated, then
46 The thread specified by
54 copies the exit status of the target thread
55 (i.e., the value that the target thread supplied to
57 into the location pointed to by
59 If the target thread was canceled, then
61 is placed in the location pointed to by
64 If multiple threads simultaneously try to join with the same thread,
65 the results are undefined.
68 is canceled, then the target thread will remain joinable
69 (i.e., it will not be detached).
74 on error, it returns an error number.
78 A deadlock was detected
79 .\" The following verified by testing on glibc 2.8/NPTL:
80 (e.g., two threads tried to join with each other);
82 .\" The following verified by testing on glibc 2.8/NPTL:
84 specifies the calling thread.
88 is not a joinable thread.
91 Another thread is already waiting to join with this thread.
92 .\" POSIX.1-2001 does not specify this error case.
99 For an explanation of the terms used in this section, see
107 Interface Attribute Value
110 T} Thread safety MT-Safe
116 POSIX.1-2001, POSIX.1-2008.
118 After a successful call to
120 the caller is guaranteed that the target thread has terminated.
121 The caller may then choose to do any clean-up that is required
122 after termination of the thread (e.g., freeing memory or other
123 resources that were allocated to the target thread).
125 Joining with a thread that has previously been joined results in
128 Failure to join with a thread that is joinable
129 (i.e., one that is not detached),
130 produces a "zombie thread".
132 since each zombie thread consumes some system resources,
133 and when enough zombie threads have accumulated,
134 it will no longer be possible to create new threads (or processes).
136 There is no pthreads analog of
137 .IR "waitpid(\-1,\ &status,\ 0)" ,
138 that is, "join with any terminated thread".
139 If you believe you need this functionality,
140 you probably need to rethink your application design.
142 All of the threads in a process are peers:
143 any thread can join with any other thread in the process.
146 .BR pthread_create (3).
148 .BR pthread_cancel (3),
149 .BR pthread_create (3),
150 .BR pthread_detach (3),
151 .BR pthread_exit (3),
152 .BR pthread_tryjoin_np (3),