]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/pthread_exit.3
perf_event_open.2: srcfix
[thirdparty/man-pages.git] / man3 / pthread_exit.3
CommitLineData
c495ab1b
MK
1.\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2.\" <mtk.manpages@gmail.com>
3.\"
93015253 4.\" %%%LICENSE_START(VERBATIM)
c495ab1b
MK
5.\" Permission is granted to make and distribute verbatim copies of this
6.\" manual provided the copyright notice and this permission notice are
7.\" preserved on all copies.
8.\"
9.\" Permission is granted to copy and distribute modified versions of this
10.\" manual under the conditions for verbatim copying, provided that the
11.\" entire resulting derived work is distributed under the terms of a
12.\" permission notice identical to this one.
13.\"
14.\" Since the Linux kernel and libraries are constantly changing, this
15.\" manual page may be incorrect or out-of-date. The author(s) assume no
16.\" responsibility for errors or omissions, or for damages resulting from
17.\" the use of the information contained herein. The author(s) may not
18.\" have taken the same level of care in the production of this manual,
19.\" which is licensed free of charge, as they might when working
20.\" professionally.
21.\"
22.\" Formatted or processed versions of this manual, if unaccompanied by
23.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 24.\" %%%LICENSE_END
c495ab1b 25.\"
460495ca 26.TH PTHREAD_EXIT 3 2015-08-08 "Linux" "Linux Programmer's Manual"
c495ab1b
MK
27.SH NAME
28pthread_exit \- terminate calling thread
29.SH SYNOPSIS
30.nf
31.B #include <pthread.h>
32
87d68647 33.BI "void pthread_exit(void *" retval );
c495ab1b
MK
34.sp
35Compile and link with \fI\-pthread\fP.
6030f2d8 36.fi
c495ab1b
MK
37.SH DESCRIPTION
38The
39.BR pthread_exit ()
40function terminates the calling thread and returns a value via
41.I retval
42that (if the thread is joinable)
43is available to another thread in the same process that calls
44.BR pthread_join (3).
45
46Any clean-up handlers established by
47.BR pthread_cleanup_push (3)
48that have not yet been popped,
49are popped (in the reverse of the order in which they were pushed)
50and executed.
51If the thread has any thread-specific data, then,
52after the clean-up handlers have been executed,
53the corresponding destructor functions are called,
54in an unspecified order.
55
56When a thread terminates,
57process-shared resources (e.g., mutexes, condition variables,
58semaphores, and file descriptors) are not released,
59and functions registered using
60.BR atexit (3)
61are not called.
62
63After the last thread in a process terminates,
64the process terminates as by calling
65.BR exit (3)
66with an exit status of zero;
67thus, process-shared resources
68are released and functions registered using
69.BR atexit (3)
70are called.
71.SH RETURN VALUE
72This function does not return to the caller.
73.SH ERRORS
74This function always succeeds.
cb63c0fc 75.SH ATTRIBUTES
b1beec8d
PH
76For an explanation of the terms used in this section, see
77.BR attributes (7).
78.TS
79allbox;
80lb lb lb
81l l l.
82Interface Attribute Value
83T{
cb63c0fc 84.BR pthread_exit ()
b1beec8d
PH
85T} Thread safety MT-Safe
86.TE
c495ab1b 87.SH CONFORMING TO
9ba60540 88POSIX.1-2001, POSIX.1-2008.
c495ab1b
MK
89.SH NOTES
90Performing a return from the start function of any thread other
91than the main thread results in an implicit call to
92.BR pthread_exit (),
93using the function's return value as the thread's exit status.
94
95To allow other threads to continue execution,
96the main thread should terminate by calling
79bb6430 97.BR pthread_exit ()
c495ab1b
MK
98rather than
99.BR exit (3).
100
101The value pointed to by
102.IR retval
103should not be located on the calling thread's stack,
104since the contents of that stack are undefined after the thread terminates.
257f73f2
MK
105.SH BUGS
106Currently,
107.\" Linux 2.6.27
108there are limitations in the kernel implementation logic for
109.BR wait (2)ing
110on a stopped thread group with a dead thread group leader.
111This can manifest in problems such as a locked terminal if a stop signal is
112sent to a foreground process whose thread group leader has already called
27d47e71 113.BR pthread_exit ().
257f73f2
MK
114.\" FIXME . review a later kernel to see if this gets fixed
115.\" http://thread.gmane.org/gmane.linux.kernel/611611
116.\" http://marc.info/?l=linux-kernel&m=122525468300823&w=2
c495ab1b
MK
117.SH SEE ALSO
118.BR pthread_create (3),
119.BR pthread_join (3),
120.BR pthreads (7)