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