tzfile.5, tzselect.8: sync from tzdb upstream
[man-pages.git] / man3 / pthread_exit.3
blob2f22a3428fc0045cd16dd1a5f43a7becc4f59129
1 '\" t
2 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
3 .\"     <mtk.manpages@gmail.com>
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH pthread_exit 3 (date) "Linux man-pages (unreleased)"
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 .PP
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 .PP
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 .PP
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 .PP
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 .ad l
61 .nh
62 .TS
63 allbox;
64 lbx lb lb
65 l l l.
66 Interface       Attribute       Value
68 .BR pthread_exit ()
69 T}      Thread safety   MT-Safe
70 .TE
71 .hy
72 .ad
73 .sp 1
74 .SH STANDARDS
75 POSIX.1-2001, POSIX.1-2008.
76 .SH NOTES
77 Performing a return from the start function of any thread other
78 than the main thread results in an implicit call to
79 .BR pthread_exit (),
80 using the function's return value as the thread's exit status.
81 .PP
82 To allow other threads to continue execution,
83 the main thread should terminate by calling
84 .BR pthread_exit ()
85 rather than
86 .BR exit (3).
87 .PP
88 The value pointed to by
89 .I retval
90 should not be located on the calling thread's stack,
91 since the contents of that stack are undefined after the thread terminates.
92 .SH BUGS
93 Currently,
94 .\" Linux 2.6.27
95 there are limitations in the kernel implementation logic for
96 .BR wait (2)ing
97 on a stopped thread group with a dead thread group leader.
98 This can manifest in problems such as a locked terminal if a stop signal is
99 sent to a foreground process whose thread group leader has already called
100 .BR pthread_exit ().
101 .\" FIXME . review a later kernel to see if this gets fixed
102 .\" http://thread.gmane.org/gmane.linux.kernel/611611
103 .\" http://marc.info/?l=linux-kernel&m=122525468300823&w=2
104 .SH SEE ALSO
105 .BR pthread_create (3),
106 .BR pthread_join (3),
107 .BR pthreads (7)