OSDN Git Service

(split) LDP: Update original to LDP v3.38.
[linuxjm/LDP_man-pages.git] / original / man3 / pthread_cleanup_push_defer_np.3
1 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2 .\"     <mtk.manpages@gmail.com>
3 .\"
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.
7 .\"
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.
12 .\"
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
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\"
24 .TH PTHREAD_CLEANUP_PUSH_DEFER_NP 3 2008-12-04 "Linux" "Linux Programmer's Manual"
25 .SH NAME
26 pthread_cleanup_push_defer_np, pthread_cleanup_pop_restore_np \- push and pop
27 thread cancellation clean-up handlers while saving cancelability type
28 .SH SYNOPSIS
29 .nf
30 .B #include <pthread.h>
31
32 .BI "void pthread_cleanup_push_defer_np(void (*" routine ")(void *),"
33 .BI "                                   void *" arg );
34 .BI "void pthread_cleanup_pop_restore_np(int " execute );
35 .fi
36 .sp
37 Compile and link with \fI\-pthread\fP.
38 .SH DESCRIPTION
39 These functions are the same as
40 .BR pthread_cleanup_push (3)
41 and
42 .BR pthread_cleanup_pop (3),
43 except for the differences noted on this page.
44
45 Like
46 .BR pthread_cleanup_push (3),
47 .BR pthread_cleanup_push_defer_np ()
48 pushes
49 .I routine
50 onto the thread's stack of cancellation clean-up handlers.
51 In addition, it also saves the thread's current cancelability type,
52 and sets the cancelability type to "deferred" (see
53 .BR pthread_setcanceltype (3));
54 this ensures that cancellation clean-up will occur
55 even if the thread's cancelability type was "asynchronous"
56 before the call.
57
58 Like
59 .BR pthread_cleanup_pop (3),
60 .BR pthread_cleanup_pop_restore_np ()
61 pops the top-most clean-up handler from the thread's
62 stack of cancellation clean-up handlers.
63 In addition, it restores the thread's cancelability
64 type to its value at the time of the matching
65 .BR pthread_cleanup_push_defer_np ().
66
67 The caller must ensure that calls to these
68 functions are paired within the same function,
69 and at the same lexical nesting level.
70 Other restrictions apply, as described in
71 .BR pthread_cleanup_push (3).
72
73 This sequence of calls:
74
75 .in +4n
76 .nf
77 pthread_cleanup_push_defer_np(routine, arg);
78 pthread_cleanup_pop_restore_np(execute);
79 .fi
80 .in
81
82 is equivalent to (but shorter and more efficient than):
83
84 .\" As far as I can see, LinuxThreads reverses the two substeps
85 .\" in the push and pop below.
86 .in +4n
87 .nf
88 int oldtype;
89
90 pthread_cleanup_push(routine, arg);
91 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype);
92 \&...
93 pthread_setcanceltype(oldtype, NULL);
94 pthread_cleanup_pop(execute);
95 .fi
96 .in
97 .\" SH VERSIONS
98 .\" Available since glibc 2.0
99 .SH CONFORMING TO
100 These functions are nonstandard GNU extensions;
101 hence the suffix "_np" (nonportable) in the names.
102 .SH SEE ALSO
103 .BR pthread_cancel (3),
104 .BR pthread_cleanup_push (3),
105 .BR pthread_setcancelstate (3),
106 .BR pthread_testcancel (3),
107 .BR pthreads (7)