Debian Codegraph @

upstream/debian-trixie/man3/pthread_exit.3

raw
1 '\" t
2 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
3 .\" <[email protected]>
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH pthread_exit 3 2024-05-02 "Linux man-pages 6.9.1"
8 .SH NAME
9 pthread_exit \- terminate calling thread
10 .SH LIBRARY
11 POSIX threads library
12 .RI ( libpthread ", " \-lpthread )
13 .SH SYNOPSIS
14 .nf
15 .B #include <pthread.h>
16 .P
17 .BI "[[noreturn]] void pthread_exit(void *" retval );
18 .fi
19 .SH DESCRIPTION
20 The
21 .BR pthread_exit ()
22 function terminates the calling thread and returns a value via
23 .I retval
24 that (if the thread is joinable)
25 is available to another thread in the same process that calls
26 .BR pthread_join (3).
27 .P
28 Any clean-up handlers established by
29 .BR pthread_cleanup_push (3)
30 that have not yet been popped,
31 are popped (in the reverse of the order in which they were pushed)
32 and executed.
33 If the thread has any thread-specific data, then,
34 after the clean-up handlers have been executed,
35 the corresponding destructor functions are called,
36 in an unspecified order.
37 .P
38 When a thread terminates,
39 process-shared resources (e.g., mutexes, condition variables,
40 semaphores, and file descriptors) are not released,
41 and functions registered using
42 .BR atexit (3)
43 are not called.
44 .P
45 After the last thread in a process terminates,
46 the process terminates as by calling
47 .BR exit (3)
48 with an exit status of zero;
49 thus, process-shared resources
50 are released and functions registered using
51 .BR atexit (3)
52 are called.
53 .SH RETURN VALUE
54 This function does not return to the caller.
55 .SH ERRORS
56 This function always succeeds.
57 .SH ATTRIBUTES
58 For an explanation of the terms used in this section, see
59 .BR attributes (7).
60 .TS
61 allbox;
62 lbx lb lb
63 l l l.
64 Interface Attribute Value
65 T{
66 .na
67 .nh
68 .BR pthread_exit ()
69 T} Thread safety MT-Safe
70 .TE
71 .SH STANDARDS
72 POSIX.1-2008.
73 .SH HISTORY
74 POSIX.1-2001.
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.
80 .P
81 To allow other threads to continue execution,
82 the main thread should terminate by calling
83 .BR pthread_exit ()
84 rather than
85 .BR exit (3).
86 .P
87 The value pointed to by
88 .I retval
89 should not be located on the calling thread's stack,
90 since the contents of that stack are undefined after the thread terminates.
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
99 .BR pthread_exit ().
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
103 .SH SEE ALSO
104 .BR pthread_create (3),
105 .BR pthread_join (3),
106 .BR pthreads (7)