|
Lines 6-12
Link Here
|
| 6 |
.Nm pthread_setcancelstate , |
6 |
.Nm pthread_setcancelstate , |
| 7 |
.Nm pthread_setcanceltype , |
7 |
.Nm pthread_setcanceltype , |
| 8 |
.Nm pthread_testcancel |
8 |
.Nm pthread_testcancel |
| 9 |
.Nd set cancelability state |
9 |
.Nd set cancellability state |
| 10 |
.Sh LIBRARY |
10 |
.Sh LIBRARY |
| 11 |
.Lb libc_r |
11 |
.Lb libc_r |
| 12 |
.Sh SYNOPSIS |
12 |
.Sh SYNOPSIS |
|
Lines 20-33
Link Here
|
| 20 |
.Sh DESCRIPTION |
20 |
.Sh DESCRIPTION |
| 21 |
The |
21 |
The |
| 22 |
.Fn pthread_setcancelstate |
22 |
.Fn pthread_setcancelstate |
| 23 |
function atomically both sets the calling thread's cancelability state |
23 |
function atomically both sets the calling thread's cancellability state |
| 24 |
to the indicated |
24 |
to the indicated |
| 25 |
.Fa state |
25 |
.Fa state |
| 26 |
and, if |
26 |
and, if |
| 27 |
.Fa oldstate |
27 |
.Fa oldstate |
| 28 |
is not |
28 |
is not |
| 29 |
.Dv NULL , |
29 |
.Dv NULL , |
| 30 |
returns the previous cancelability state at the location referenced by |
30 |
returns the previous cancellability state at the location referenced by |
| 31 |
.Fa oldstate . |
31 |
.Fa oldstate . |
| 32 |
Legal values for |
32 |
Legal values for |
| 33 |
.Fa state |
33 |
.Fa state |
|
Lines 38-51
Link Here
|
| 38 |
.Pp |
38 |
.Pp |
| 39 |
The |
39 |
The |
| 40 |
.Fn pthread_setcanceltype |
40 |
.Fn pthread_setcanceltype |
| 41 |
function atomically both sets the calling thread's cancelability type |
41 |
function atomically both sets the calling thread's cancellability type |
| 42 |
to the indicated |
42 |
to the indicated |
| 43 |
.Fa type |
43 |
.Fa type |
| 44 |
and, if |
44 |
and, if |
| 45 |
.Fa oldtype |
45 |
.Fa oldtype |
| 46 |
is not |
46 |
is not |
| 47 |
.Dv NULL , |
47 |
.Dv NULL , |
| 48 |
returns the previous cancelability type at the location referenced by |
48 |
returns the previous cancellability type at the location referenced by |
| 49 |
.Fa oldtype . |
49 |
.Fa oldtype . |
| 50 |
Legal values for |
50 |
Legal values for |
| 51 |
.Fa type |
51 |
.Fa type |
|
Lines 54-60
Link Here
|
| 54 |
and |
54 |
and |
| 55 |
.Dv PTHREAD_CANCEL_ASYNCHRONOUS . |
55 |
.Dv PTHREAD_CANCEL_ASYNCHRONOUS . |
| 56 |
.Pp |
56 |
.Pp |
| 57 |
The cancelability state and type of any newly created threads, including the |
57 |
The cancellability state and type of any newly created threads, including the |
| 58 |
thread in which |
58 |
thread in which |
| 59 |
.Fn main |
59 |
.Fn main |
| 60 |
was first invoked, are |
60 |
was first invoked, are |
|
Lines 68-100
Link Here
|
| 68 |
function creates a cancellation point in the calling thread. |
68 |
function creates a cancellation point in the calling thread. |
| 69 |
The |
69 |
The |
| 70 |
.Fn pthread_testcancel |
70 |
.Fn pthread_testcancel |
| 71 |
function has no effect if cancelability is disabled. |
71 |
function has no effect if cancellability is disabled. |
| 72 |
.Pp |
72 |
.Pp |
| 73 |
.Ss Cancelability States |
73 |
.Ss Cancelability States |
| 74 |
The cancelability state of a thread determines the action taken upon |
74 |
The cancellability state of a thread determines the action taken upon |
| 75 |
receipt of a cancellation request. |
75 |
receipt of a cancellation request. |
| 76 |
The thread may control cancellation in |
76 |
The thread may control cancellation in |
| 77 |
a number of ways. |
77 |
a number of ways. |
| 78 |
.Pp |
78 |
.Pp |
| 79 |
Each thread maintains its own |
79 |
Each thread maintains its own |
| 80 |
.Dq cancelability state |
80 |
.Dq cancellability state |
| 81 |
which may be encoded in two bits: |
81 |
which may be encoded in two bits: |
| 82 |
.Bl -hang |
82 |
.Bl -hang |
| 83 |
.It Em Cancelability Enable |
83 |
.It Em Cancelability Enable |
| 84 |
When cancelability is |
84 |
.br |
|
|
85 |
When cancellability is |
| 85 |
.Dv PTHREAD_CANCEL_DISABLE , |
86 |
.Dv PTHREAD_CANCEL_DISABLE , |
| 86 |
cancellation requests against the target thread are held pending. |
87 |
cancellation requests against the target thread are held pending. |
| 87 |
.It Em Cancelability Type |
88 |
.It Em Cancelability Type |
| 88 |
When cancelability is enabled and the cancelability type is |
89 |
.br |
|
|
90 |
When cancellability is enabled and the cancellability type is |
| 89 |
.Dv PTHREAD_CANCEL_ASYNCHRONOUS , |
91 |
.Dv PTHREAD_CANCEL_ASYNCHRONOUS , |
| 90 |
new or pending cancellation requests may be acted upon at any time. |
92 |
new or pending cancellation requests may be acted upon at any time. |
| 91 |
When cancelability is enabled and the cancelability type is |
93 |
When cancellability is enabled and the cancellability type is |
| 92 |
.Dv PTHREAD_CANCEL_DEFERRED , |
94 |
.Dv PTHREAD_CANCEL_DEFERRED , |
| 93 |
cancellation requests are held pending until a cancellation point (see |
95 |
cancellation requests are held pending until a cancellation point (see |
| 94 |
below) is reached. |
96 |
below) is reached. |
| 95 |
If cancelability is disabled, the setting of the |
97 |
If cancellability is disabled, the setting of the |
| 96 |
cancelability type has no immediate effect as all cancellation requests |
98 |
cancellability type has no immediate effect as all cancellation requests |
| 97 |
are held pending; however, once cancelability is enabled again the new |
99 |
are held pending; however, once cancellability is enabled again the new |
| 98 |
type will be in effect. |
100 |
type will be in effect. |
| 99 |
.El |
101 |
.El |
| 100 |
.Ss Cancellation Points |
102 |
.Ss Cancellation Points |
|
Lines 147-173
Link Here
|
| 147 |
Objects may depend |
149 |
Objects may depend |
| 148 |
on other objects. |
150 |
on other objects. |
| 149 |
.Pp |
151 |
.Pp |
| 150 |
First, cancelability should only be disabled on entry to an object, never |
152 |
First, cancellability should only be disabled on entry to an object, never |
| 151 |
explicitly enabled. |
153 |
explicitly enabled. |
| 152 |
On exit from an object, the cancelability state should |
154 |
On exit from an object, the cancellability state should |
| 153 |
always be restored to its value on entry to the object. |
155 |
always be restored to its value on entry to the object. |
| 154 |
.Pp |
156 |
.Pp |
| 155 |
This follows from a modularity argument: if the client of an object (or the |
157 |
This follows from a modularity argument: if the client of an object (or the |
| 156 |
client of an object that uses that object) has disabled cancelability, it is |
158 |
client of an object that uses that object) has disabled cancellability, it is |
| 157 |
because the client doesn't want to have to worry about how to clean up if the |
159 |
because the client doesn't want to have to worry about how to clean up if the |
| 158 |
thread is canceled while executing some sequence of actions. |
160 |
thread is canceled while executing some sequence of actions. |
| 159 |
If an object |
161 |
If an object |
| 160 |
is called in such a state and it enables cancelability and a cancellation |
162 |
is called in such a state and it enables cancellability and a cancellation |
| 161 |
request is pending for that thread, then the thread will be canceled, |
163 |
request is pending for that thread, then the thread will be canceled, |
| 162 |
contrary to the wish of the client that disabled. |
164 |
contrary to the wish of the client that disabled. |
| 163 |
.Pp |
165 |
.Pp |
| 164 |
Second, the cancelability type may be explicitly set to either |
166 |
Second, the cancellability type may be explicitly set to either |
| 165 |
.Em deferred |
167 |
.Em deferred |
| 166 |
or |
168 |
or |
| 167 |
.Em asynchronous |
169 |
.Em asynchronous |
| 168 |
upon entry to an object. |
170 |
upon entry to an object. |
| 169 |
But as with the cancelability state, on exit from |
171 |
But as with the cancellability state, on exit from |
| 170 |
an object that cancelability type should always be restored to its value on |
172 |
an object that cancellability type should always be restored to its value on |
| 171 |
entry to the object. |
173 |
entry to the object. |
| 172 |
.Pp |
174 |
.Pp |
| 173 |
Finally, only functions that are cancel-safe may be called from a thread that |
175 |
Finally, only functions that are cancel-safe may be called from a thread that |