1thr_join(3C) Standard C Library Functions thr_join(3C)
2
3
4
6 thr_join - wait for thread termination
7
9 cc -mt [ flag... ] file...[ library... ]
10 #include <thread.h>
11
12 int thr_join(thread_t thread, thread_t *departed, void **status);
13
14
16 The thr_join() function suspends processing of the calling thread until
17 the target thread completes. The thread argument must be a member of
18 the current process and cannot be a detached thread. See thr_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 thr_join() function will not block processing of the calling
26 thread if the target thread has already terminated.
27
28
29 If a thr_join() call returns successfully with a non-null status argu‐
30 ment, the value passed to thr_exit(3C) by the terminating thread will
31 be placed in the location referenced by status.
32
33
34 If the target thread ID is 0, thr_join() finds and returns the status
35 of a terminated undetached thread in the process. If no such thread
36 exists, it suspends processing of the calling thread until a thread for
37 which no other thread is waiting enters that state, at which time it
38 returns successfully, or until all other threads in the process are
39 either daemon threads or threads waiting in thr_join(), in which case
40 it returns EDEADLK. See NOTES.
41
42
43 If departed is not NULL, it points to a location that is set to the ID
44 of the terminated thread if thr_join() returns successfully.
45
47 If successful, thr_join() returns 0. Otherwise, an error number is
48 returned to indicate the error.
49
51 EDEADLK A joining deadlock would occur, such as when a thread
52 attempts to wait for itself, or the calling thread is wait‐
53 ing for any thread to exit and only daemon threads or wait‐
54 ing threads exist in the process.
55
56
57 ESRCH No undetached thread could be found corresponding to the
58 given thread ID.
59
60
62 See attributes(5) for descriptions of the following attributes:
63
64
65
66
67 ┌─────────────────────────────┬─────────────────────────────┐
68 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
69 ├─────────────────────────────┼─────────────────────────────┤
70 │MT-Level │MT-Safe │
71 └─────────────────────────────┴─────────────────────────────┘
72
74 thr_create(3C), thr_exit(3C), wait(3C), attributes(5), standards(5)
75
77 Using thr_join(3C) in the following syntax,
78
79 while (thr_join(0, NULL, NULL) == 0);
80
81
82
83 will wait for the termination of all non-daemon threads, excluding
84 threads that are themselves waiting in thr_join().
85
86
87
88SunOS 5.11 27 Mar 2000 thr_join(3C)