1PTHREAD_EXIT(3P) POSIX Programmer's Manual PTHREAD_EXIT(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 pthread_exit - thread termination
13
15 #include <pthread.h>
16
17 void pthread_exit(void *value_ptr);
18
19
21 The pthread_exit() function shall terminate the calling thread and make
22 the value value_ptr available to any successful join with the terminat‐
23 ing thread. Any cancellation cleanup handlers that have been pushed and
24 not yet popped shall be popped in the reverse order that they were
25 pushed and then executed. After all cancellation cleanup handlers have
26 been executed, if the thread has any thread-specific data, appropriate
27 destructor functions shall be called in an unspecified order. Thread
28 termination does not release any application visible process resources,
29 including, but not limited to, mutexes and file descriptors, nor does
30 it perform any process-level cleanup actions, including, but not lim‐
31 ited to, calling any atexit() routines that may exist.
32
33 An implicit call to pthread_exit() is made when a thread other than the
34 thread in which main() was first invoked returns from the start routine
35 that was used to create it. The function's return value shall serve as
36 the thread's exit status.
37
38 The behavior of pthread_exit() is undefined if called from a cancella‐
39 tion cleanup handler or destructor function that was invoked as a
40 result of either an implicit or explicit call to pthread_exit().
41
42 After a thread has terminated, the result of access to local (auto)
43 variables of the thread is undefined. Thus, references to local vari‐
44 ables of the exiting thread should not be used for the pthread_exit()
45 value_ptr parameter value.
46
47 The process shall exit with an exit status of 0 after the last thread
48 has been terminated. The behavior shall be as if the implementation
49 called exit() with a zero argument at thread termination time.
50
52 The pthread_exit() function cannot return to its caller.
53
55 No errors are defined.
56
57 The following sections are informative.
58
60 None.
61
63 None.
64
66 The normal mechanism by which a thread terminates is to return from the
67 routine that was specified in the pthread_create() call that started
68 it. The pthread_exit() function provides the capability for a thread to
69 terminate without requiring a return from the start routine of that
70 thread, thereby providing a function analogous to exit().
71
72 Regardless of the method of thread termination, any cancellation
73 cleanup handlers that have been pushed and not yet popped are executed,
74 and the destructors for any existing thread-specific data are executed.
75 This volume of IEEE Std 1003.1-2001 requires that cancellation cleanup
76 handlers be popped and called in order. After all cancellation cleanup
77 handlers have been executed, thread-specific data destructors are
78 called, in an unspecified order, for each item of thread-specific data
79 that exists in the thread. This ordering is necessary because cancella‐
80 tion cleanup handlers may rely on thread-specific data.
81
82 As the meaning of the status is determined by the application (except
83 when the thread has been canceled, in which case it is PTHREAD_CAN‐
84 CELED), the implementation has no idea what an illegal status value is,
85 which is why no address error checking is done.
86
88 None.
89
91 exit(), pthread_create(), pthread_join(), the Base Definitions volume
92 of IEEE Std 1003.1-2001, <pthread.h>
93
95 Portions of this text are reprinted and reproduced in electronic form
96 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
97 -- Portable Operating System Interface (POSIX), The Open Group Base
98 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
99 Electrical and Electronics Engineers, Inc and The Open Group. In the
100 event of any discrepancy between this version and the original IEEE and
101 The Open Group Standard, the original IEEE and The Open Group Standard
102 is the referee document. The original Standard can be obtained online
103 at http://www.opengroup.org/unix/online.html .
104
105
106
107IEEE/The Open Group 2003 PTHREAD_EXIT(3P)