1 .\" $FreeBSD: src/lib/libc_r/man/pthread_testcancel.3,v 1.2.2.3 2001/08/17 15:42:52 ru Exp $
3 .Dt PTHREAD_TESTCANCEL 3
6 .Nm pthread_setcancelstate ,
7 .Nm pthread_setcanceltype ,
9 .Nd set cancelability state
11 .Fd #include <pthread.h>
13 .Fo pthread_setcancelstate
18 .Fo pthread_setcanceltype
23 .Fo pthread_testcancel
28 .Fn pthread_setcancelstate
29 function atomically both sets the calling thread's cancelability state
32 and returns the previous cancelability state at the location referenced by
37 .Dv PTHREAD_CANCEL_ENABLE
39 .Dv PTHREAD_CANCEL_DISABLE .
42 .Fn pthread_setcanceltype
43 function atomically both sets the calling thread's cancelability type
46 and returns the previous cancelability type at the location referenced by
51 .Dv PTHREAD_CANCEL_DEFERRED
53 .Dv PTHREAD_CANCEL_ASYNCHRONOUS .
55 The cancelability state and type of any newly created threads, including the
58 was first invoked, are
59 .Dv PTHREAD_CANCEL_ENABLE
61 .Dv PTHREAD_CANCEL_DEFERRED
65 .Fn pthread_testcancel
66 function creates a cancellation point in the calling thread.
68 .Fn pthread_testcancel
69 function has no effect if cancelability is disabled.
71 .Ss Cancelability States
72 The cancelability state of a thread determines the action taken upon
73 receipt of a cancellation request.
74 The thread may control cancellation in
77 Each thread maintains its own
78 .Dq cancelability state
79 which may be encoded in two bits:
81 .It Em Cancelability Enable
83 .Dv PTHREAD_CANCEL_DISABLE ,
84 cancellation requests against the target thread are held pending.
85 .It Em Cancelability Type
86 When cancelability is enabled and the cancelability type is
87 .Dv PTHREAD_CANCEL_ASYNCHRONOUS ,
88 new or pending cancellation requests may be acted upon at any time.
89 When cancelability is enabled and the cancelability type is
90 .Dv PTHREAD_CANCEL_DEFERRED ,
91 cancellation requests are held pending until a cancellation point (see
93 If cancelability is disabled, the setting of the
94 cancelability type has no immediate effect as all cancellation requests
95 are held pending; however, once cancelability is enabled again the new
96 type will be in effect.
98 .Ss Cancellation Points
99 Cancellation points will occur when a thread is executing the following
109 .Fn pthread_cond_timedwait ,
110 .Fn pthread_cond_wait ,
112 .Fn pthread_testcancel ,
125 .Fn pthread_setcancelstate
127 .Fn pthread_setcanceltype
128 functions will return zero.
129 Otherwise, an error number shall be returned to
133 .Fn pthread_setcancelstate
135 .Fn pthread_setcanceltype
136 functions are used to control the points at which a thread may be
137 asynchronously canceled.
138 For cancellation control to be usable in modular
139 fashion, some rules must be followed.
141 For purposes of this discussion, consider an object to be a generalization
143 It is a set of procedures and global variables written as
144 a unit and called by clients not known by the object.
148 First, cancelability should only be disabled on entry to an object, never
150 On exit from an object, the cancelability state should
151 always be restored to its value on entry to the object.
153 This follows from a modularity argument: if the client of an object (or the
154 client of an object that uses that object) has disabled cancelability, it is
155 because the client doesn't want to have to worry about how to clean up if the
156 thread is canceled while executing some sequence of actions.
158 is called in such a state and it enables cancelability and a cancellation
159 request is pending for that thread, then the thread will be canceled,
160 contrary to the wish of the client that disabled.
162 Second, the cancelability type may be explicitly set to either
166 upon entry to an object.
167 But, as with the cancelability state, on exit from
168 an object that cancelability type should always be restored to its value on
171 Finally, only functions that are cancel-safe may be called from a thread that
172 is asynchronously cancelable.
175 .Fn pthread_setcancelstate
179 The specified state is not
180 .Dv PTHREAD_CANCEL_ENABLE
182 .Dv PTHREAD_CANCEL_DISABLE .
186 .Fn pthread_setcanceltype
190 The specified state is not
191 .Dv PTHREAD_CANCEL_DEFERRED
193 .Dv PTHREAD_CANCEL_ASYNCHRONOUS .
198 .Fn pthread_testcancel
202 This man page was written by
203 .An David Leonard Aq d@openbsd.org
207 .Xr pthread_cancel 3 .