1PTHREAD_JOIN(3) Linux Programmer's Manual PTHREAD_JOIN(3)
2
3
4
6 pthread_join - join with a terminated thread
7
9 #include <pthread.h>
10
11 int pthread_join(pthread_t thread, void **retval);
12
13 Compile and link with -pthread.
14
16 The pthread_join() function waits for the thread specified by thread to
17 terminate. If that thread has already terminated, then pthread_join()
18 returns immediately. The thread specified by thread must be joinable.
19
20 If retval is not NULL, then pthread_join() copies the exit status of
21 the target thread (i.e., the value that the target thread supplied to
22 pthread_exit(3)) into the location pointed to by *retval. If the tar‐
23 get thread was canceled, then PTHREAD_CANCELED is placed in *retval.
24
25 If multiple threads simultaneously try to join with the same thread,
26 the results are undefined. If the thread calling pthread_join() is
27 canceled, then the target thread will remain joinable (i.e., it will
28 not be detached).
29
31 On success, pthread_join() returns 0; on error, it returns an error
32 number.
33
35 EDEADLK
36 A deadlock was detected (e.g., two threads tried to join with
37 each other); or thread specifies the calling thread.
38
39 EINVAL thread is not a joinable thread.
40
41 EINVAL Another thread is already waiting to join with this thread.
42
43 ESRCH No thread with the ID thread could be found.
44
46 POSIX.1-2001.
47
49 After a successful call to pthread_join(), the caller is guaranteed
50 that the target thread has terminated.
51
52 Joining with a thread that has previously been joined results in unde‐
53 fined behavior.
54
55 Failure to join with a thread that is joinable (i.e., one that is not
56 detached), produces a "zombie thread". Avoid doing this, since each
57 zombie thread consumes some system resources, and when enough zombie
58 threads have accumulated, it will no longer be possible to create new
59 threads (or processes).
60
61 There is no pthreads analog of waitpid(-1, &status, 0), that is, "join
62 with any terminated thread". If you believe you need this functional‐
63 ity, you probably need to rethink your application design.
64
65 All of the threads in a process are peers: any thread can join with any
66 other thread in the process.
67
69 See pthread_create(3).
70
72 pthread_cancel(3), pthread_create(3), pthread_detach(3),
73 pthread_exit(3), pthread_tryjoin_np(3), pthreads(7)
74
76 This page is part of release 3.25 of the Linux man-pages project. A
77 description of the project, and information about reporting bugs, can
78 be found at http://www.kernel.org/doc/man-pages/.
79
80
81
82Linux 2008-11-27 PTHREAD_JOIN(3)