1pthread_join(3C)         Standard C Library Functions         pthread_join(3C)
2
3
4

NAME

6       pthread_join - wait for thread termination
7

SYNOPSIS

9       cc -mt [ flag... ] file... -lpthread [ library... ]
10       #include <pthread.h>
11
12       int pthread_join(pthread_t thread, void **status);
13
14

DESCRIPTION

16       The  pthread_join()  function suspends processing of the calling thread
17       until the target thread completes. thread must be a member of the  cur‐
18       rent  process  and  it  cannot  be  a detached thread. See pthread_cre‐
19       ate(3C).
20
21
22       If two or more threads wait for the same thread to complete,  all  will
23       suspend processing until the thread has terminated, and then one thread
24       will return successfully and the others will return with  an  error  of
25       ESRCH.  The  pthread_join()  function  will not block processing of the
26       calling thread if the target thread has already terminated.
27
28
29       If a pthread_join() call returns successfully with  a  non-null  status
30       argument,  the  value  passed  to  pthread_exit(3C)  by the terminating
31       thread will be placed in the location referenced by status.
32
33
34       If the pthread_join() calling thread  is  cancelled,  then  the  target
35       thread  will  remain  joinable  by pthread_join(). However, the calling
36       thread may set up a cancellation cleanup handler on thread prior to the
37       join   call,   which   may   detach   the   target  thread  by  calling
38       pthread_detach(3C). See pthread_detach(3C) and pthread_cancel(3C).
39

RETURN VALUES

41       If successful, pthread_join() returns 0. Otherwise, an error number  is
42       returned to indicate the error.
43

ERRORS

45       EDEADLK    A  joining  deadlock  would  occur,  such  as  when a thread
46                  attempts to wait for itself.
47
48
49       EINVAL     The thread  corresponding  to  the  given  thread  ID  is  a
50                  detached thread.
51
52
53       ESRCH      No  thread  could be found corresponding to the given thread
54                  ID.
55
56

ATTRIBUTES

58       See attributes(5) for descriptions of the following attributes:
59
60
61
62
63       ┌─────────────────────────────┬─────────────────────────────┐
64       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
65       ├─────────────────────────────┼─────────────────────────────┤
66       │Interface Stability          │Standard                     │
67       ├─────────────────────────────┼─────────────────────────────┤
68       │MT-Level                     │MT-Safe                      │
69       └─────────────────────────────┴─────────────────────────────┘
70

SEE ALSO

72       pthread_cancel(3C),       pthread_create(3C),       pthread_detach(3C),
73       pthread_exit(3C), wait(3C), attributes(5), standards(5)
74

NOTES

76       The pthread_join(3C) function must specify the thread ID for whose ter‐
77       mination it will wait.
78
79
80       Calling  pthread_join()  also   "detaches"   the   thread;   that   is,
81       pthread_join() includes the effect of the pthread_detach() function. If
82       a thread were to  be  cancelled  when  blocked  in  pthread_join(),  an
83       explicit  detach would have to be performed in the cancellation cleanup
84       handler. The pthread_detach() function exists primarily for  this  pur‐
85       pose.
86
87
88
89SunOS 5.11                        23 Mar 2005                 pthread_join(3C)
Impressum