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