]>
Commit | Line | Data |
---|---|---|
a1eaacb1 | 1 | '\" t |
ebdd7ee1 MK |
2 | .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk |
3 | .\" <mtk.manpages@gmail.com> | |
4 | .\" | |
5fbde956 | 5 | .\" SPDX-License-Identifier: Linux-man-pages-copyleft |
ebdd7ee1 | 6 | .\" |
4c1c5274 | 7 | .TH pthread_join 3 (date) "Linux man-pages (unreleased)" |
ebdd7ee1 MK |
8 | .SH NAME |
9 | pthread_join \- join with a terminated thread | |
574dfc58 AC |
10 | .SH LIBRARY |
11 | POSIX threads library | |
8fc3b2cf | 12 | .RI ( libpthread ", " \-lpthread ) |
ebdd7ee1 MK |
13 | .SH SYNOPSIS |
14 | .nf | |
15 | .B #include <pthread.h> | |
dbfe9c70 | 16 | .PP |
ebdd7ee1 MK |
17 | .BI "int pthread_join(pthread_t " thread ", void **" retval ); |
18 | .fi | |
ebdd7ee1 MK |
19 | .SH DESCRIPTION |
20 | The | |
21 | .BR pthread_join () | |
22 | function waits for the thread specified by | |
1ae6b2c7 | 23 | .I thread |
ebdd7ee1 MK |
24 | to terminate. |
25 | If that thread has already terminated, then | |
26 | .BR pthread_join () | |
27 | returns immediately. | |
28 | The thread specified by | |
29 | .I thread | |
30 | must be joinable. | |
847e0d88 | 31 | .PP |
ebdd7ee1 MK |
32 | If |
33 | .I retval | |
34 | is not NULL, then | |
35 | .BR pthread_join () | |
36 | copies the exit status of the target thread | |
37 | (i.e., the value that the target thread supplied to | |
38 | .BR pthread_exit (3)) | |
39 | into the location pointed to by | |
919b0ce0 | 40 | .IR retval . |
ebdd7ee1 MK |
41 | If the target thread was canceled, then |
42 | .B PTHREAD_CANCELED | |
919b0ce0 MK |
43 | is placed in the location pointed to by |
44 | .IR retval . | |
847e0d88 | 45 | .PP |
ebdd7ee1 MK |
46 | If multiple threads simultaneously try to join with the same thread, |
47 | the results are undefined. | |
48 | If the thread calling | |
49 | .BR pthread_join () | |
50 | is canceled, then the target thread will remain joinable | |
51 | (i.e., it will not be detached). | |
52 | .SH RETURN VALUE | |
53 | On success, | |
54 | .BR pthread_join () | |
55 | returns 0; | |
56 | on error, it returns an error number. | |
57 | .SH ERRORS | |
58 | .TP | |
59 | .B EDEADLK | |
60 | A deadlock was detected | |
61 | .\" The following verified by testing on glibc 2.8/NPTL: | |
62 | (e.g., two threads tried to join with each other); | |
63 | or | |
64 | .\" The following verified by testing on glibc 2.8/NPTL: | |
65 | .I thread | |
66 | specifies the calling thread. | |
67 | .TP | |
68 | .B EINVAL | |
69 | .I thread | |
70 | is not a joinable thread. | |
bbb08de3 MK |
71 | .TP |
72 | .B EINVAL | |
73 | Another thread is already waiting to join with this thread. | |
74 | .\" POSIX.1-2001 does not specify this error case. | |
ebdd7ee1 MK |
75 | .TP |
76 | .B ESRCH | |
48718eb3 MK |
77 | No thread with the ID |
78 | .I thread | |
79 | could be found. | |
acc271be ZL |
80 | .SH ATTRIBUTES |
81 | For an explanation of the terms used in this section, see | |
82 | .BR attributes (7). | |
83 | .TS | |
84 | allbox; | |
c466875e | 85 | lbx lb lb |
acc271be ZL |
86 | l l l. |
87 | Interface Attribute Value | |
88 | T{ | |
9e54434e BR |
89 | .na |
90 | .nh | |
acc271be ZL |
91 | .BR pthread_join () |
92 | T} Thread safety MT-Safe | |
93 | .TE | |
847e0d88 | 94 | .sp 1 |
3113c7f3 | 95 | .SH STANDARDS |
4131356c AC |
96 | POSIX.1-2008. |
97 | .SH HISTORY | |
98 | POSIX.1-2001. | |
ebdd7ee1 MK |
99 | .SH NOTES |
100 | After a successful call to | |
c162db87 | 101 | .BR pthread_join (), |
ebdd7ee1 | 102 | the caller is guaranteed that the target thread has terminated. |
46305699 MK |
103 | The caller may then choose to do any clean-up that is required |
104 | after termination of the thread (e.g., freeing memory or other | |
105 | resources that were allocated to the target thread). | |
847e0d88 | 106 | .PP |
ebdd7ee1 | 107 | Joining with a thread that has previously been joined results in |
240c2fa0 | 108 | undefined behavior. |
847e0d88 | 109 | .PP |
ebdd7ee1 MK |
110 | Failure to join with a thread that is joinable |
111 | (i.e., one that is not detached), | |
112 | produces a "zombie thread". | |
113 | Avoid doing this, | |
114 | since each zombie thread consumes some system resources, | |
115 | and when enough zombie threads have accumulated, | |
116 | it will no longer be possible to create new threads (or processes). | |
847e0d88 | 117 | .PP |
ebdd7ee1 | 118 | There is no pthreads analog of |
cd415e73 | 119 | .IR "waitpid(\-1,\ &status,\ 0)" , |
ebdd7ee1 MK |
120 | that is, "join with any terminated thread". |
121 | If you believe you need this functionality, | |
122 | you probably need to rethink your application design. | |
847e0d88 | 123 | .PP |
ebdd7ee1 MK |
124 | All of the threads in a process are peers: |
125 | any thread can join with any other thread in the process. | |
a14af333 | 126 | .SH EXAMPLES |
ebdd7ee1 MK |
127 | See |
128 | .BR pthread_create (3). | |
129 | .SH SEE ALSO | |
130 | .BR pthread_cancel (3), | |
131 | .BR pthread_create (3), | |
132 | .BR pthread_detach (3), | |
133 | .BR pthread_exit (3), | |
33a5ffc9 | 134 | .BR pthread_tryjoin_np (3), |
ebdd7ee1 | 135 | .BR pthreads (7) |