1thr_exit(3C) Standard C Library Functions thr_exit(3C)
2
3
4
6 thr_exit - terminate the calling thread
7
9 cc -mt [ flag... ] file...[ library... ]
10 #include <thread.h>
11
12 void thr_exit(void *status);
13
14
16 The thr_exit() function terminates the calling thread, in a similar way
17 that exit(3C) terminates the calling process. If the calling thread is
18 not detached, then the thread's ID and the exit status specified by
19 status are retained. The value status is then made available to any
20 successful join with the terminating thread (see thr_join(3C)); other‐
21 wise, status is disregarded allowing the thread's ID to be reclaimed
22 immediately.
23
24
25 Any cancellation cleanup handlers that have been pushed and not yet
26 popped are popped in the reverse order that they were pushed and then
27 executed. After all cancellation cleanup handlers have been executed,
28 if the thread has any thread-specific data, appropriate destructor
29 functions will be called in an unspecified order. Thread termination
30 does not release any application visible process resources, including,
31 but not limited to, mutexes and file descriptors, nor does it perform
32 any process level cleanup actions, including, but not limited to, call‐
33 ing any atexit() routines that might exist.
34
35
36 An exiting thread runs with all signals blocked. All thread termination
37 functions, including cancellation cleanup handlers and thread-specific
38 data destructor functions, are called with all signals blocked.
39
40
41 If any thread, including the main() thread, calls thr_exit(), only
42 that thread will exit.
43
44
45 If main() returns or exits (either implicitly or explicitly), or any
46 thread explicitly calls exit(), the entire process will exit.
47
48
49 The behavior of thr_exit() is undefined if called from a cancellation
50 cleanup handler or destructor function that was invoked as a result of
51 either an implicit or explicit call to thr_exit().
52
53
54 After a thread has terminated, the result of access to local (auto)
55 variables of the thread is undefined. Thus, references to local vari‐
56 ables of the exiting thread should not be used for the thr_exit() sta‐
57 tus parameter value.
58
59
60 If any thread (except the main() thread) implicitly or explicitly
61 returns, the result is the same as if the thread called thr_exit() and
62 it will return the value of status as the exit code.
63
64
65 The process will terminate with an exit status of 0 after the last non-
66 daemon thread has terminated (including the main() thread). This behav‐
67 ior is the same as if the application had called exit() with a 0 argu‐
68 ment at thread termination time.
69
71 The thr_exit() function cannot return to its caller.
72
74 No errors are defined.
75
77 See attributes(5) for descriptions of the following attributes:
78
79
80
81
82 ┌─────────────────────────────┬─────────────────────────────┐
83 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
84 ├─────────────────────────────┼─────────────────────────────┤
85 │MT-Level │MT-Safe │
86 └─────────────────────────────┴─────────────────────────────┘
87
89 exit(3C), thr_create(3C), thr_join(3C), thr_keycreate(3C),
90 attributes(5), standards(5)
91
93 Although only POSIX implements cancellation, cancellation can be used
94 with Solaris threads, due to their interoperability.
95
96
97 The status argument should not reference any variables local to the
98 calling thread.
99
100
101
102SunOS 5.11 2 Nov 2007 thr_exit(3C)