1 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
24 .TH PTHREAD_CLEANUP_PUSH_DEFER_NP 3 2008-12-04 "Linux" "Linux Programmer's Manual"
26 pthread_cleanup_push_defer_np, pthread_cleanup_pop_restore_np \- push and pop
27 thread cancellation clean-up handlers while saving cancelability type
30 .B #include <pthread.h>
32 .BI "void pthread_cleanup_push_defer_np(void (*" routine ")(void *),"
34 .BI "void pthread_cleanup_pop_restore_np(int " execute );
36 Compile and link with \fI\-pthread\fP.
38 These functions are the same as
39 .BR pthread_cleanup_push (3)
41 .BR pthread_cleanup_pop (3),
42 except for the differences noted on this page.
45 .BR pthread_cleanup_push (3),
46 .BR pthread_cleanup_push_defer_np ()
49 onto the thread's stack of cancellation clean-up handlers.
50 In addition, it also saves the thread's current cancelability type,
51 and sets the cancelability type to "deferred" (see
52 .BR pthread_setcanceltype (3));
53 this ensures that cancellation clean-up will occur
54 even if the thread's cancelability type was "asynchronous"
58 .BR pthread_cleanup_pop (3),
59 .BR pthread_cleanup_pop_restore_np ()
60 pops the top-most clean-up handler from the thread's
61 stack of cancellation clean-up handlers.
62 In addition, it restores the thread's cancelability
63 type to its value at the time of the matching
64 .BR pthread_cleanup_push_defer_np ().
66 The caller must ensure that calls to these
67 functions are paired within the same function,
68 and at the same lexical nesting level.
69 Other restrictions apply, as described in
70 .BR pthread_cleanup_push (3).
72 This sequence of calls:
76 pthread_cleanup_push_defer_np(routine, arg);
77 pthread_cleanup_pop_restore_np(execute);
81 is equivalent to (but shorter and more efficient than):
83 .\" As far as I can see, LinuxThreads reverses the two substeps
84 .\" in the push and pop below.
89 pthread_cleanup_push(routine, arg);
90 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype);
92 pthread_setcanceltype(oldtype, NULL);
93 pthread_cleanup_pop(execute);
97 .\" Available since glibc 2.0
99 These functions are nonstandard GNU extensions;
100 hence the suffix "_np" (nonportable) in the names.
102 .BR pthread_cancel (3),
103 .BR pthread_cleanup_push (3),
104 .BR pthread_setcancelstate (3),
105 .BR pthread_testcancel (3),