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