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

176 lines
4.5 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of PTHREAD_CLEANUP_PUSH_DEFER_NP</TITLE>
</HEAD><BODY>
<H1>PTHREAD_CLEANUP_PUSH_DEFER_NP</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_cleanup_push_defer_np, pthread_cleanup_pop_restore_np - push and pop
thread cancellation clean-up handlers while saving cancelability type
<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_cleanup_push_defer_np(void (*</B><I>routine</I><B>)(void *),</B>
<B> void *</B><I>arg</I><B>);</B>
<B>void pthread_cleanup_pop_restore_np(int </B><I>execute</I><B>);</B>
</PRE>
<P>
Compile and link with <I>-pthread</I>.
<P>
Feature Test Macro Requirements for glibc (see
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
<P>
<B>pthread_cleanup_push_defer_np</B>(),
<B>pthread_cleanup_pop_defer_np</B>():
<DL COMPACT><DT id="1"><DD>
_GNU_SOURCE
</DL>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
These functions are the same as
<B><A HREF="/cgi-bin/man/man2html?3+pthread_cleanup_push">pthread_cleanup_push</A></B>(3)
and
<B><A HREF="/cgi-bin/man/man2html?3+pthread_cleanup_pop">pthread_cleanup_pop</A></B>(3),
except for the differences noted on this page.
<P>
Like
<B><A HREF="/cgi-bin/man/man2html?3+pthread_cleanup_push">pthread_cleanup_push</A></B>(3),
<B>pthread_cleanup_push_defer_np</B>()
pushes
<I>routine</I>
onto the thread's stack of cancellation clean-up handlers.
In addition, it also saves the thread's current cancelability type,
and sets the cancelability type to &quot;deferred&quot; (see
<B><A HREF="/cgi-bin/man/man2html?3+pthread_setcanceltype">pthread_setcanceltype</A></B>(3));
this ensures that cancellation clean-up will occur
even if the thread's cancelability type was &quot;asynchronous&quot;
before the call.
<P>
Like
<B><A HREF="/cgi-bin/man/man2html?3+pthread_cleanup_pop">pthread_cleanup_pop</A></B>(3),
<B>pthread_cleanup_pop_restore_np</B>()
pops the top-most clean-up handler from the thread's
stack of cancellation clean-up handlers.
In addition, it restores the thread's cancelability
type to its value at the time of the matching
<B>pthread_cleanup_push_defer_np</B>().
<P>
The caller must ensure that calls to these
functions are paired within the same function,
and at the same lexical nesting level.
Other restrictions apply, as described in
<B><A HREF="/cgi-bin/man/man2html?3+pthread_cleanup_push">pthread_cleanup_push</A></B>(3).
<P>
This sequence of calls:
<P>
pthread_cleanup_push_defer_np(routine, arg);
pthread_cleanup_pop_restore_np(execute);
<P>
is equivalent to (but shorter and more efficient than):
<P>
int oldtype;
<P>
pthread_cleanup_push(routine, arg);
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &amp;oldtype);
...
pthread_setcanceltype(oldtype, NULL);
pthread_cleanup_pop(execute);
<A NAME="lbAE">&nbsp;</A>
<H2>CONFORMING TO</H2>
These functions are nonstandard GNU extensions;
hence the suffix &quot;_np&quot; (nonportable) in the names.
<A NAME="lbAF">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?3+pthread_cancel">pthread_cancel</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+pthread_cleanup_push">pthread_cleanup_push</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+pthread_setcancelstate">pthread_setcancelstate</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+pthread_testcancel">pthread_testcancel</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?7+pthreads">pthreads</A></B>(7)
<A NAME="lbAG">&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="2"><A HREF="#lbAB">NAME</A><DD>
<DT id="3"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="4"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="5"><A HREF="#lbAE">CONFORMING TO</A><DD>
<DT id="6"><A HREF="#lbAF">SEE ALSO</A><DD>
<DT id="7"><A HREF="#lbAG">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>