1 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .TH PTHREAD_CLEANUP_PUSH_DEFER_NP 3 2021-03-22 "Linux man-pages (unreleased)"
8 pthread_cleanup_push_defer_np, pthread_cleanup_pop_restore_np \- push and pop
9 thread cancelation clean-up handlers while saving cancelability type
12 .RI ( libpthread ", " \-lpthread )
15 .B #include <pthread.h>
17 .BI "void pthread_cleanup_push_defer_np(void (*" routine ")(void *), void *" arg );
18 .BI "void pthread_cleanup_pop_restore_np(int " execute );
22 Feature Test Macro Requirements for glibc (see
23 .BR feature_test_macros (7)):
26 .BR pthread_cleanup_push_defer_np (),
27 .BR pthread_cleanup_pop_defer_np ():
32 These functions are the same as
33 .BR pthread_cleanup_push (3)
35 .BR pthread_cleanup_pop (3),
36 except for the differences noted on this page.
39 .BR pthread_cleanup_push (3),
40 .BR pthread_cleanup_push_defer_np ()
43 onto the thread's stack of cancelation clean-up handlers.
44 In addition, it also saves the thread's current cancelability type,
45 and sets the cancelability type to "deferred" (see
46 .BR pthread_setcanceltype (3));
47 this ensures that cancelation clean-up will occur
48 even if the thread's cancelability type was "asynchronous"
52 .BR pthread_cleanup_pop (3),
53 .BR pthread_cleanup_pop_restore_np ()
54 pops the top-most clean-up handler from the thread's
55 stack of cancelation clean-up handlers.
56 In addition, it restores the thread's cancelability
57 type to its value at the time of the matching
58 .BR pthread_cleanup_push_defer_np ().
60 The caller must ensure that calls to these
61 functions are paired within the same function,
62 and at the same lexical nesting level.
63 Other restrictions apply, as described in
64 .BR pthread_cleanup_push (3).
66 This sequence of calls:
70 pthread_cleanup_push_defer_np(routine, arg);
71 pthread_cleanup_pop_restore_np(execute);
75 is equivalent to (but shorter and more efficient than):
77 .\" As far as I can see, LinuxThreads reverses the two substeps
78 .\" in the push and pop below.
83 pthread_cleanup_push(routine, arg);
84 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype);
86 pthread_setcanceltype(oldtype, NULL);
87 pthread_cleanup_pop(execute);
91 .\" Available since glibc 2.0
93 These functions are nonstandard GNU extensions;
94 hence the suffix "_np" (nonportable) in the names.
96 .BR pthread_cancel (3),
97 .BR pthread_cleanup_push (3),
98 .BR pthread_setcancelstate (3),
99 .BR pthread_testcancel (3),