]>
Commit | Line | Data |
---|---|---|
ebdd7ee1 MK |
1 | .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk |
2 | .\" <mtk.manpages@gmail.com> | |
3 | .\" | |
93015253 | 4 | .\" %%%LICENSE_START(VERBATIM) |
ebdd7ee1 MK |
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. | |
4b72fb64 | 24 | .\" %%%LICENSE_END |
ebdd7ee1 | 25 | .\" |
4b8c67d9 | 26 | .TH PTHREAD_JOIN 3 2017-09-15 "Linux" "Linux Programmer's Manual" |
ebdd7ee1 MK |
27 | .SH NAME |
28 | pthread_join \- join with a terminated thread | |
29 | .SH SYNOPSIS | |
30 | .nf | |
31 | .B #include <pthread.h> | |
dbfe9c70 | 32 | .PP |
ebdd7ee1 MK |
33 | .BI "int pthread_join(pthread_t " thread ", void **" retval ); |
34 | .fi | |
68e4db0a | 35 | .PP |
ebdd7ee1 MK |
36 | Compile and link with \fI\-pthread\fP. |
37 | .SH DESCRIPTION | |
38 | The | |
39 | .BR pthread_join () | |
40 | function waits for the thread specified by | |
41 | .IR thread | |
42 | to terminate. | |
43 | If that thread has already terminated, then | |
44 | .BR pthread_join () | |
45 | returns immediately. | |
46 | The thread specified by | |
47 | .I thread | |
48 | must be joinable. | |
847e0d88 | 49 | .PP |
ebdd7ee1 MK |
50 | If |
51 | .I retval | |
52 | is not NULL, then | |
53 | .BR pthread_join () | |
54 | copies the exit status of the target thread | |
55 | (i.e., the value that the target thread supplied to | |
56 | .BR pthread_exit (3)) | |
57 | into the location pointed to by | |
919b0ce0 | 58 | .IR retval . |
ebdd7ee1 MK |
59 | If the target thread was canceled, then |
60 | .B PTHREAD_CANCELED | |
919b0ce0 MK |
61 | is placed in the location pointed to by |
62 | .IR retval . | |
847e0d88 | 63 | .PP |
ebdd7ee1 MK |
64 | If multiple threads simultaneously try to join with the same thread, |
65 | the results are undefined. | |
66 | If the thread calling | |
67 | .BR pthread_join () | |
68 | is canceled, then the target thread will remain joinable | |
69 | (i.e., it will not be detached). | |
70 | .SH RETURN VALUE | |
71 | On success, | |
72 | .BR pthread_join () | |
73 | returns 0; | |
74 | on error, it returns an error number. | |
75 | .SH ERRORS | |
76 | .TP | |
77 | .B EDEADLK | |
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); | |
81 | or | |
82 | .\" The following verified by testing on glibc 2.8/NPTL: | |
83 | .I thread | |
84 | specifies the calling thread. | |
85 | .TP | |
86 | .B EINVAL | |
87 | .I thread | |
88 | is not a joinable thread. | |
bbb08de3 MK |
89 | .TP |
90 | .B EINVAL | |
91 | Another thread is already waiting to join with this thread. | |
92 | .\" POSIX.1-2001 does not specify this error case. | |
ebdd7ee1 MK |
93 | .TP |
94 | .B ESRCH | |
48718eb3 MK |
95 | No thread with the ID |
96 | .I thread | |
97 | could be found. | |
acc271be ZL |
98 | .SH ATTRIBUTES |
99 | For an explanation of the terms used in this section, see | |
100 | .BR attributes (7). | |
101 | .TS | |
102 | allbox; | |
103 | lb lb lb | |
104 | l l l. | |
105 | Interface Attribute Value | |
106 | T{ | |
107 | .BR pthread_join () | |
108 | T} Thread safety MT-Safe | |
109 | .TE | |
847e0d88 | 110 | .sp 1 |
ebdd7ee1 | 111 | .SH CONFORMING TO |
a2f2f3a3 | 112 | POSIX.1-2001, POSIX.1-2008. |
ebdd7ee1 MK |
113 | .SH NOTES |
114 | After a successful call to | |
c162db87 | 115 | .BR pthread_join (), |
ebdd7ee1 | 116 | the caller is guaranteed that the target thread has terminated. |
46305699 MK |
117 | The caller may then choose to do any clean-up that is required |
118 | after termination of the thread (e.g., freeing memory or other | |
119 | resources that were allocated to the target thread). | |
847e0d88 | 120 | .PP |
ebdd7ee1 | 121 | Joining with a thread that has previously been joined results in |
240c2fa0 | 122 | undefined behavior. |
847e0d88 | 123 | .PP |
ebdd7ee1 MK |
124 | Failure to join with a thread that is joinable |
125 | (i.e., one that is not detached), | |
126 | produces a "zombie thread". | |
127 | Avoid doing this, | |
128 | since each zombie thread consumes some system resources, | |
129 | and when enough zombie threads have accumulated, | |
130 | it will no longer be possible to create new threads (or processes). | |
847e0d88 | 131 | .PP |
ebdd7ee1 MK |
132 | There is no pthreads analog of |
133 | .IR "waitpid(-1,\ &status,\ 0)" , | |
134 | that is, "join with any terminated thread". | |
135 | If you believe you need this functionality, | |
136 | you probably need to rethink your application design. | |
847e0d88 | 137 | .PP |
ebdd7ee1 MK |
138 | All of the threads in a process are peers: |
139 | any thread can join with any other thread in the process. | |
140 | .SH EXAMPLE | |
141 | See | |
142 | .BR pthread_create (3). | |
143 | .SH SEE ALSO | |
144 | .BR pthread_cancel (3), | |
145 | .BR pthread_create (3), | |
146 | .BR pthread_detach (3), | |
147 | .BR pthread_exit (3), | |
33a5ffc9 | 148 | .BR pthread_tryjoin_np (3), |
ebdd7ee1 | 149 | .BR pthreads (7) |