Changes.old: Add missing entry in 5.13 changelog
[man-pages.git] / man3 / pthread_cleanup_push_defer_np.3
blobc5096d11ec9187103cd9873c063bba6fe3b2beb7
1 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2 .\"     <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .TH PTHREAD_CLEANUP_PUSH_DEFER_NP 3 2021-03-22 "Linux" "Linux Programmer's Manual"
27 .SH NAME
28 pthread_cleanup_push_defer_np, pthread_cleanup_pop_restore_np \- push and pop
29 thread cancellation clean-up handlers while saving cancelability type
30 .SH SYNOPSIS
31 .nf
32 .B #include <pthread.h>
33 .PP
34 .BI "void pthread_cleanup_push_defer_np(void (*" routine ")(void *), void *" arg );
35 .BI "void pthread_cleanup_pop_restore_np(int " execute );
36 .fi
37 .PP
38 Compile and link with \fI\-pthread\fP.
39 .PP
40 .RS -4
41 Feature Test Macro Requirements for glibc (see
42 .BR feature_test_macros (7)):
43 .RE
44 .PP
45 .BR pthread_cleanup_push_defer_np (),
46 .BR pthread_cleanup_pop_defer_np ():
47 .nf
48     _GNU_SOURCE
49 .fi
50 .SH DESCRIPTION
51 These functions are the same as
52 .BR pthread_cleanup_push (3)
53 and
54 .BR pthread_cleanup_pop (3),
55 except for the differences noted on this page.
56 .PP
57 Like
58 .BR pthread_cleanup_push (3),
59 .BR pthread_cleanup_push_defer_np ()
60 pushes
61 .I routine
62 onto the thread's stack of cancellation clean-up handlers.
63 In addition, it also saves the thread's current cancelability type,
64 and sets the cancelability type to "deferred" (see
65 .BR pthread_setcanceltype (3));
66 this ensures that cancellation clean-up will occur
67 even if the thread's cancelability type was "asynchronous"
68 before the call.
69 .PP
70 Like
71 .BR pthread_cleanup_pop (3),
72 .BR pthread_cleanup_pop_restore_np ()
73 pops the top-most clean-up handler from the thread's
74 stack of cancellation clean-up handlers.
75 In addition, it restores the thread's cancelability
76 type to its value at the time of the matching
77 .BR pthread_cleanup_push_defer_np ().
78 .PP
79 The caller must ensure that calls to these
80 functions are paired within the same function,
81 and at the same lexical nesting level.
82 Other restrictions apply, as described in
83 .BR pthread_cleanup_push (3).
84 .PP
85 This sequence of calls:
86 .PP
87 .in +4n
88 .EX
89 pthread_cleanup_push_defer_np(routine, arg);
90 pthread_cleanup_pop_restore_np(execute);
91 .EE
92 .in
93 .PP
94 is equivalent to (but shorter and more efficient than):
95 .PP
96 .\" As far as I can see, LinuxThreads reverses the two substeps
97 .\" in the push and pop below.
98 .in +4n
99 .EX
100 int oldtype;
102 pthread_cleanup_push(routine, arg);
103 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype);
104 \&...
105 pthread_setcanceltype(oldtype, NULL);
106 pthread_cleanup_pop(execute);
109 .\" SH VERSIONS
110 .\" Available since glibc 2.0
111 .SH CONFORMING TO
112 These functions are nonstandard GNU extensions;
113 hence the suffix "_np" (nonportable) in the names.
114 .SH SEE ALSO
115 .BR pthread_cancel (3),
116 .BR pthread_cleanup_push (3),
117 .BR pthread_setcancelstate (3),
118 .BR pthread_testcancel (3),
119 .BR pthreads (7)