Blame man3/pthread_exit.3

Packit 7cfc04
.\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
Packit 7cfc04
.\"     <mtk.manpages@gmail.com>
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM)
Packit 7cfc04
.\" Permission is granted to make and distribute verbatim copies of this
Packit 7cfc04
.\" manual provided the copyright notice and this permission notice are
Packit 7cfc04
.\" preserved on all copies.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Permission is granted to copy and distribute modified versions of this
Packit 7cfc04
.\" manual under the conditions for verbatim copying, provided that the
Packit 7cfc04
.\" entire resulting derived work is distributed under the terms of a
Packit 7cfc04
.\" permission notice identical to this one.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Since the Linux kernel and libraries are constantly changing, this
Packit 7cfc04
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
Packit 7cfc04
.\" responsibility for errors or omissions, or for damages resulting from
Packit 7cfc04
.\" the use of the information contained herein.  The author(s) may not
Packit 7cfc04
.\" have taken the same level of care in the production of this manual,
Packit 7cfc04
.\" which is licensed free of charge, as they might when working
Packit 7cfc04
.\" professionally.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Formatted or processed versions of this manual, if unaccompanied by
Packit 7cfc04
.\" the source, must acknowledge the copyright and authors of this work.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.TH PTHREAD_EXIT 3 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
pthread_exit \- terminate calling thread
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.nf
Packit 7cfc04
.B #include <pthread.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "void pthread_exit(void *" retval );
Packit 7cfc04
.PP
Packit 7cfc04
Compile and link with \fI\-pthread\fP.
Packit 7cfc04
.fi
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
The
Packit 7cfc04
.BR pthread_exit ()
Packit 7cfc04
function terminates the calling thread and returns a value via
Packit 7cfc04
.I retval
Packit 7cfc04
that (if the thread is joinable)
Packit 7cfc04
is available to another thread in the same process that calls
Packit 7cfc04
.BR pthread_join (3).
Packit 7cfc04
.PP
Packit 7cfc04
Any clean-up handlers established by
Packit 7cfc04
.BR pthread_cleanup_push (3)
Packit 7cfc04
that have not yet been popped,
Packit 7cfc04
are popped (in the reverse of the order in which they were pushed)
Packit 7cfc04
and executed.
Packit 7cfc04
If the thread has any thread-specific data, then,
Packit 7cfc04
after the clean-up handlers have been executed,
Packit 7cfc04
the corresponding destructor functions are called,
Packit 7cfc04
in an unspecified order.
Packit 7cfc04
.PP
Packit 7cfc04
When a thread terminates,
Packit 7cfc04
process-shared resources (e.g., mutexes, condition variables,
Packit 7cfc04
semaphores, and file descriptors) are not released,
Packit 7cfc04
and functions registered using
Packit 7cfc04
.BR atexit (3)
Packit 7cfc04
are not called.
Packit 7cfc04
.PP
Packit 7cfc04
After the last thread in a process terminates,
Packit 7cfc04
the process terminates as by calling
Packit 7cfc04
.BR exit (3)
Packit 7cfc04
with an exit status of zero;
Packit 7cfc04
thus, process-shared resources
Packit 7cfc04
are released and functions registered using
Packit 7cfc04
.BR atexit (3)
Packit 7cfc04
are called.
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
This function does not return to the caller.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
This function always succeeds.
Packit 7cfc04
.SH ATTRIBUTES
Packit 7cfc04
For an explanation of the terms used in this section, see
Packit 7cfc04
.BR attributes (7).
Packit 7cfc04
.TS
Packit 7cfc04
allbox;
Packit 7cfc04
lb lb lb
Packit 7cfc04
l l l.
Packit 7cfc04
Interface	Attribute	Value
Packit 7cfc04
T{
Packit 7cfc04
.BR pthread_exit ()
Packit 7cfc04
T}	Thread safety	MT-Safe
Packit 7cfc04
.TE
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
POSIX.1-2001, POSIX.1-2008.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
Performing a return from the start function of any thread other
Packit 7cfc04
than the main thread results in an implicit call to
Packit 7cfc04
.BR pthread_exit (),
Packit 7cfc04
using the function's return value as the thread's exit status.
Packit 7cfc04
.PP
Packit 7cfc04
To allow other threads to continue execution,
Packit 7cfc04
the main thread should terminate by calling
Packit 7cfc04
.BR pthread_exit ()
Packit 7cfc04
rather than
Packit 7cfc04
.BR exit (3).
Packit 7cfc04
.PP
Packit 7cfc04
The value pointed to by
Packit 7cfc04
.IR retval
Packit 7cfc04
should not be located on the calling thread's stack,
Packit 7cfc04
since the contents of that stack are undefined after the thread terminates.
Packit 7cfc04
.SH BUGS
Packit 7cfc04
Currently,
Packit 7cfc04
.\" Linux 2.6.27
Packit 7cfc04
there are limitations in the kernel implementation logic for
Packit 7cfc04
.BR wait (2)ing
Packit 7cfc04
on a stopped thread group with a dead thread group leader.
Packit 7cfc04
This can manifest in problems such as a locked terminal if a stop signal is
Packit 7cfc04
sent to a foreground process whose thread group leader has already called
Packit 7cfc04
.BR pthread_exit ().
Packit 7cfc04
.\" FIXME . review a later kernel to see if this gets fixed
Packit 7cfc04
.\" http://thread.gmane.org/gmane.linux.kernel/611611
Packit 7cfc04
.\" http://marc.info/?l=linux-kernel&m=122525468300823&w=2
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR pthread_create (3),
Packit 7cfc04
.BR pthread_join (3),
Packit 7cfc04
.BR pthreads (7)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.