]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/pthread_exit.3
3fa5e64a5035433689c4a8f27866ad9d360af11a
[thirdparty/man-pages.git] / man3 / pthread_exit.3
1 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .TH PTHREAD_EXIT 3 2021-03-22 "Linux man-pages (unreleased)" "Linux Programmer's Manual"
7 .SH NAME
8 pthread_exit \- terminate calling thread
9 .SH LIBRARY
10 POSIX threads library
11 .RI ( libpthread ", " \-lpthread )
12 .SH SYNOPSIS
13 .nf
14 .B #include <pthread.h>
15 .PP
16 .BI "noreturn void pthread_exit(void *" retval );
17 .fi
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).
26 .PP
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.
36 .PP
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.
43 .PP
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.
56 .SH ATTRIBUTES
57 For an explanation of the terms used in this section, see
58 .BR attributes (7).
59 .ad l
60 .nh
61 .TS
62 allbox;
63 lbx lb lb
64 l l l.
65 Interface Attribute Value
66 T{
67 .BR pthread_exit ()
68 T} Thread safety MT-Safe
69 .TE
70 .hy
71 .ad
72 .sp 1
73 .SH STANDARDS
74 POSIX.1-2001, POSIX.1-2008.
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 .PP
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 .PP
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)