]>
Commit | Line | Data |
---|---|---|
c495ab1b MK |
1 | .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk |
2 | .\" <mtk.manpages@gmail.com> | |
3 | .\" | |
5fbde956 | 4 | .\" SPDX-License-Identifier: Linux-man-pages-copyleft |
c495ab1b | 5 | .\" |
1d767b55 | 6 | .TH PTHREAD_EXIT 3 2021-03-22 "Linux" "Linux Programmer's Manual" |
c495ab1b MK |
7 | .SH NAME |
8 | pthread_exit \- terminate calling thread | |
9 | .SH SYNOPSIS | |
10 | .nf | |
11 | .B #include <pthread.h> | |
dbfe9c70 | 12 | .PP |
6c49c14b | 13 | .BI "noreturn void pthread_exit(void *" retval ); |
68e4db0a | 14 | .PP |
c495ab1b | 15 | Compile and link with \fI\-pthread\fP. |
6030f2d8 | 16 | .fi |
c495ab1b MK |
17 | .SH DESCRIPTION |
18 | The | |
19 | .BR pthread_exit () | |
20 | function terminates the calling thread and returns a value via | |
21 | .I retval | |
22 | that (if the thread is joinable) | |
23 | is available to another thread in the same process that calls | |
24 | .BR pthread_join (3). | |
847e0d88 | 25 | .PP |
c495ab1b MK |
26 | Any clean-up handlers established by |
27 | .BR pthread_cleanup_push (3) | |
28 | that have not yet been popped, | |
29 | are popped (in the reverse of the order in which they were pushed) | |
30 | and executed. | |
31 | If the thread has any thread-specific data, then, | |
32 | after the clean-up handlers have been executed, | |
33 | the corresponding destructor functions are called, | |
34 | in an unspecified order. | |
847e0d88 | 35 | .PP |
c495ab1b MK |
36 | When a thread terminates, |
37 | process-shared resources (e.g., mutexes, condition variables, | |
38 | semaphores, and file descriptors) are not released, | |
39 | and functions registered using | |
40 | .BR atexit (3) | |
41 | are not called. | |
847e0d88 | 42 | .PP |
c495ab1b MK |
43 | After the last thread in a process terminates, |
44 | the process terminates as by calling | |
45 | .BR exit (3) | |
46 | with an exit status of zero; | |
47 | thus, process-shared resources | |
48 | are released and functions registered using | |
49 | .BR atexit (3) | |
50 | are called. | |
51 | .SH RETURN VALUE | |
52 | This function does not return to the caller. | |
53 | .SH ERRORS | |
54 | This function always succeeds. | |
cb63c0fc | 55 | .SH ATTRIBUTES |
b1beec8d PH |
56 | For an explanation of the terms used in this section, see |
57 | .BR attributes (7). | |
c466875e MK |
58 | .ad l |
59 | .nh | |
b1beec8d PH |
60 | .TS |
61 | allbox; | |
c466875e | 62 | lbx lb lb |
b1beec8d PH |
63 | l l l. |
64 | Interface Attribute Value | |
65 | T{ | |
cb63c0fc | 66 | .BR pthread_exit () |
b1beec8d PH |
67 | T} Thread safety MT-Safe |
68 | .TE | |
c466875e MK |
69 | .hy |
70 | .ad | |
71 | .sp 1 | |
c495ab1b | 72 | .SH CONFORMING TO |
9ba60540 | 73 | POSIX.1-2001, POSIX.1-2008. |
c495ab1b MK |
74 | .SH NOTES |
75 | Performing a return from the start function of any thread other | |
76 | than the main thread results in an implicit call to | |
77 | .BR pthread_exit (), | |
78 | using the function's return value as the thread's exit status. | |
847e0d88 | 79 | .PP |
c495ab1b MK |
80 | To allow other threads to continue execution, |
81 | the main thread should terminate by calling | |
79bb6430 | 82 | .BR pthread_exit () |
c495ab1b MK |
83 | rather than |
84 | .BR exit (3). | |
847e0d88 | 85 | .PP |
c495ab1b MK |
86 | The value pointed to by |
87 | .IR retval | |
88 | should not be located on the calling thread's stack, | |
89 | since the contents of that stack are undefined after the thread terminates. | |
257f73f2 MK |
90 | .SH BUGS |
91 | Currently, | |
92 | .\" Linux 2.6.27 | |
93 | there are limitations in the kernel implementation logic for | |
94 | .BR wait (2)ing | |
95 | on a stopped thread group with a dead thread group leader. | |
96 | This can manifest in problems such as a locked terminal if a stop signal is | |
97 | sent to a foreground process whose thread group leader has already called | |
27d47e71 | 98 | .BR pthread_exit (). |
257f73f2 MK |
99 | .\" FIXME . review a later kernel to see if this gets fixed |
100 | .\" http://thread.gmane.org/gmane.linux.kernel/611611 | |
101 | .\" http://marc.info/?l=linux-kernel&m=122525468300823&w=2 | |
c495ab1b MK |
102 | .SH SEE ALSO |
103 | .BR pthread_create (3), | |
104 | .BR pthread_join (3), | |
105 | .BR pthreads (7) |