OSDN Git Service

dc5571f30ae733a592c976103dc5ddedb5703ee0
[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 .\" %%%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 2008-12-04 "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
34 .BI "void pthread_cleanup_push_defer_np(void (*" routine ")(void *),"
35 .BI "                                   void *" arg );
36 .BI "void pthread_cleanup_pop_restore_np(int " execute );
37 .fi
38 .sp
39 Compile and link with \fI\-pthread\fP.
40 .SH DESCRIPTION
41 These functions are the same as
42 .BR pthread_cleanup_push (3)
43 and
44 .BR pthread_cleanup_pop (3),
45 except for the differences noted on this page.
46
47 Like
48 .BR pthread_cleanup_push (3),
49 .BR pthread_cleanup_push_defer_np ()
50 pushes
51 .I routine
52 onto the thread's stack of cancellation clean-up handlers.
53 In addition, it also saves the thread's current cancelability type,
54 and sets the cancelability type to "deferred" (see
55 .BR pthread_setcanceltype (3));
56 this ensures that cancellation clean-up will occur
57 even if the thread's cancelability type was "asynchronous"
58 before the call.
59
60 Like
61 .BR pthread_cleanup_pop (3),
62 .BR pthread_cleanup_pop_restore_np ()
63 pops the top-most clean-up handler from the thread's
64 stack of cancellation clean-up handlers.
65 In addition, it restores the thread's cancelability
66 type to its value at the time of the matching
67 .BR pthread_cleanup_push_defer_np ().
68
69 The caller must ensure that calls to these
70 functions are paired within the same function,
71 and at the same lexical nesting level.
72 Other restrictions apply, as described in
73 .BR pthread_cleanup_push (3).
74
75 This sequence of calls:
76
77 .in +4n
78 .nf
79 pthread_cleanup_push_defer_np(routine, arg);
80 pthread_cleanup_pop_restore_np(execute);
81 .fi
82 .in
83
84 is equivalent to (but shorter and more efficient than):
85
86 .\" As far as I can see, LinuxThreads reverses the two substeps
87 .\" in the push and pop below.
88 .in +4n
89 .nf
90 int oldtype;
91
92 pthread_cleanup_push(routine, arg);
93 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype);
94 \&...
95 pthread_setcanceltype(oldtype, NULL);
96 pthread_cleanup_pop(execute);
97 .fi
98 .in
99 .\" SH VERSIONS
100 .\" Available since glibc 2.0
101 .SH CONFORMING TO
102 These functions are nonstandard GNU extensions;
103 hence the suffix "_np" (nonportable) in the names.
104 .SH SEE ALSO
105 .BR pthread_cancel (3),
106 .BR pthread_cleanup_push (3),
107 .BR pthread_setcancelstate (3),
108 .BR pthread_testcancel (3),
109 .BR pthreads (7)
110 .SH COLOPHON
111 This page is part of release 3.67 of the Linux
112 .I man-pages
113 project.
114 A description of the project,
115 information about reporting bugs,
116 and the latest version of this page,
117 can be found at
118 \%http://www.kernel.org/doc/man\-pages/.