man-pages/man3/pthread_exit.3.html
2021-03-31 01:06:50 +01:00

181 lines
4.8 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of PTHREAD_EXIT</TITLE>
</HEAD><BODY>
<H1>PTHREAD_EXIT</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
pthread_exit - terminate calling thread
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/pthread.h">pthread.h</A>&gt;</B>
<B>void pthread_exit(void *</B><I>retval</I><B>);</B>
Compile and link with <I>-pthread</I>.
</PRE>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The
<B>pthread_exit</B>()
function terminates the calling thread and returns a value via
<I>retval</I>
that (if the thread is joinable)
is available to another thread in the same process that calls
<B><A HREF="/cgi-bin/man/man2html?3+pthread_join">pthread_join</A></B>(3).
<P>
Any clean-up handlers established by
<B><A HREF="/cgi-bin/man/man2html?3+pthread_cleanup_push">pthread_cleanup_push</A></B>(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.
<P>
When a thread terminates,
process-shared resources (e.g., mutexes, condition variables,
semaphores, and file descriptors) are not released,
and functions registered using
<B><A HREF="/cgi-bin/man/man2html?3+atexit">atexit</A></B>(3)
are not called.
<P>
After the last thread in a process terminates,
the process terminates as by calling
<B><A HREF="/cgi-bin/man/man2html?3+exit">exit</A></B>(3)
with an exit status of zero;
thus, process-shared resources
are released and functions registered using
<B><A HREF="/cgi-bin/man/man2html?3+atexit">atexit</A></B>(3)
are called.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
This function does not return to the caller.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
This function always succeeds.
<A NAME="lbAG">&nbsp;</A>
<H2>ATTRIBUTES</H2>
For an explanation of the terms used in this section, see
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
<TABLE BORDER>
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
<TR VALIGN=top><TD>
<B>pthread_exit</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
</TABLE>
<A NAME="lbAH">&nbsp;</A>
<H2>CONFORMING TO</H2>
POSIX.1-2001, POSIX.1-2008.
<A NAME="lbAI">&nbsp;</A>
<H2>NOTES</H2>
Performing a return from the start function of any thread other
than the main thread results in an implicit call to
<B>pthread_exit</B>(),
using the function's return value as the thread's exit status.
<P>
To allow other threads to continue execution,
the main thread should terminate by calling
<B>pthread_exit</B>()
rather than
<B><A HREF="/cgi-bin/man/man2html?3+exit">exit</A></B>(3).
<P>
The value pointed to by
<I>retval</I>
should not be located on the calling thread's stack,
since the contents of that stack are undefined after the thread terminates.
<A NAME="lbAJ">&nbsp;</A>
<H2>BUGS</H2>
Currently,
there are limitations in the kernel implementation logic for
<B><A HREF="/cgi-bin/man/man2html?2+wait">wait</A></B>(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
<B>pthread_exit</B>().
<A NAME="lbAK">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?3+pthread_create">pthread_create</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+pthread_join">pthread_join</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?7+pthreads">pthreads</A></B>(7)
<A NAME="lbAL">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
<DT id="2"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="3"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="4"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="5"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="6"><A HREF="#lbAG">ATTRIBUTES</A><DD>
<DT id="7"><A HREF="#lbAH">CONFORMING TO</A><DD>
<DT id="8"><A HREF="#lbAI">NOTES</A><DD>
<DT id="9"><A HREF="#lbAJ">BUGS</A><DD>
<DT id="10"><A HREF="#lbAK">SEE ALSO</A><DD>
<DT id="11"><A HREF="#lbAL">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:53 GMT, March 31, 2021
</BODY>
</HTML>