File: pthread_cancel.3

package info (click to toggle)
manpages-ja 0.5.0.0.20061115-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 19,788 kB
  • ctags: 4
  • sloc: sh: 13,215; perl: 157; makefile: 117
file content (443 lines) | stat: -rw-r--r-- 13,979 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
.\"   Copyright (C) 1994-1999 Free Software Foundation, Inc.
.\"
.\"   Permission is granted to make and distribute verbatim copies of
.\" this manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\"   Permission is granted to copy and distribute modified versions of
.\" this manual under the conditions for verbatim copying, provided that
.\" the entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one.
.\"
.\"   Permission is granted to copy and distribute translations of this
.\" manual into another language, under the above conditions for modified
.\" versions, except that this permission notice may be stated in a
.\" translation approved by the Foundation.
.\"
.\" Copyright (C) 1999 Xavier Leroy.
.\" 
.\" Japanese Version Copyright (C) 2000 WAKABAYASHI, Takeyasu
.\"         all rights reserved.
.\" Translated on Fri Jan 14 16:50:24 JST 2000
.\"         by WAKABAYASHI, Takeyasu <twakaba@eco.toyama-u.ac.jp>
.\"
.\" 
.\" .TH PTHREAD_CANCEL 3 LinuxThreads
.\"
.\"
.\" .SH NAME
.\" pthread_cancel, pthread_setcancelstate, pthread_setcanceltype, pthread_testcancel \- thread cancellation
.\"
.\" .SH SYNOPSIS
.\" .B #include <pthread.h>
.\"
.\" .BI "int pthread_cancel(pthread_t " thread ");"
.\"
.\" .BI "int pthread_setcancelstate(int " state ", int *" oldstate ");"
.\"
.\" .BI "int pthread_setcanceltype(int " type ", int *" oldtype ");"
.\"
.\" .BI "void pthread_testcancel(void);"
.TH PTHREAD_CANCEL 3 LinuxThreads


.SH NAME
pthread_cancel, pthread_setcancelstate, pthread_setcanceltype, pthread_testcancel \- åɤμä

.SH 
.B #include <pthread.h>

.BI "int pthread_cancel(pthread_t " thread ");"

.BI "int pthread_setcancelstate(int " state ", int *" oldstate ");"

.BI "int pthread_setcanceltype(int " type ", int *" oldtype ");"

.BI "void pthread_testcancel(void);"

.\" .SH DESCRIPTION
.\"
.\" Cancellation is the mechanism by which a thread can terminate the
.\" execution of another thread. More precisely, a thread can send a
.\" cancellation request to another thread. Depending on its settings, the
.\" target thread can then either ignore the request, honor it
.\" immediately, or defer it till it reaches a cancellation point.
.SH 

äϡ륹åɤ¾Υåɤμ¹Ԥλ뤳Ȥǽ
ˤᥫ˥Ǥ롣Τˤϡåɤ¾ΥåɤФ
׵뤳ȤǤ롣꼡ǡɸΥåɤϡ׵̵
ꡢľ˼¸ꡢäݥȤ˻ޤǤ׵μ¹
Ǥ롣

.\" When a thread eventually honors a cancellation request, it performs as
.\" if 
.\" .B "pthread_exit(PTHREAD_CANCELED)"
.\" has been called at that point:
.\" all cleanup handlers are executed in reverse order, finalization
.\" functions for thread-specific data are called, and finally the thread
.\" stops executing with the return value 
.\" .BR "PTHREAD_CANCELED" .
.\" See
.\" .BR "pthread_exit" (3)
.\" for more information.
åɤǽŪ˼ä׵¸ݤˤϡϤ
.B "pthread_exit(PTHREAD_CANCELED)"
λǸƤӽФ줿Τ褦˿񤦡ʤƤΥ꡼
åץϥɥ餬ս˼¹Ԥ졢åɸͭǡνλؿ
ƤӽФ졢Ǹ˥åɤϡ֤
.BR "PTHREAD_CANCEL"
Ǽ¹Ԥߤ롣ܤ
.BR "pthread_exit" (3)
򸫤衣

.\" .B "pthread_cancel"
.\" sends a cancellation request to the thread denoted
.\" by the 
.\" .I "thread"
.\" argument.
.BR "pthread_cancel"

.I "thread"
ǻꤵ줿åɤФơä׵롣

.\" .B "pthread_setcancelstate"
.\" changes the cancellation state for the
.\" calling thread -- that is, whether cancellation requests are ignored
.\" or not. The 
.\" .I "state"
.\" argument is the new cancellation state: either
.\" .B "PTHREAD_CANCEL_ENABLE"
.\" to enable cancellation, or
.\" .B "PTHREAD_CANCEL_DISABLE"
.\" to disable cancellation (cancellation
.\" requests are ignored). If 
.\" .I "oldstate"
.\" is not 
.\" .BR "NULL" ,
.\" the previous
.\" cancellation state is stored in the location pointed to by 
.\" .IR "oldstate" ,
.\" and can thus be restored later by another call to
.\" .BR "pthread_setcancelstate" .
.B "pthread_setcancelstate"
ϡƤӽФåɤμä֤ѹ롣
ʤä׵뤫ݤѹ롣
.I "state"
Ͽʼä֤Ǥ롣ϼäǽˤ
.B "PTHREAD_CANCEL_ENABLE"
⤷ϡäԲǽˤ(ä׵̵뤹)
.B "PTHREAD_CANCEL_DISABLE"
Τ줫Ǥ롣
.I "oldstate"

.BR "NULL"
ǤʤСμä֤
.IR "oldstate"
ؤ˳Ǽ졢äơ̤
.BR "pthread_setcancelstate"
θƤӽФˤꡢ뤳ȤǤ롣

.\" .B "pthread_setcanceltype"
.\" changes the type of responses to cancellation
.\" requests for the calling thread: asynchronous (immediate) or deferred.
.\" The 
.\" .I "type"
.\" argument is the new cancellation type: either
.\" .B "PTHREAD_CANCEL_ASYNCHRONOUS"
.\" to cancel the calling thread as soon as
.\" the cancellation request is received, or 
.\" .B "PTHREAD_CANCEL_DEFERRED"
.\" to
.\" keep the cancellation request pending until the next cancellation
.\" point. If 
.\" .I "oldtype"
.\" is not 
.\" .BR "NULL" ,
.\" the previous
.\" cancellation state is stored in the location pointed to by 
.\" .IR "oldtype" ,
.\" and can thus be restored later by another call to
.\" .BR "pthread_setcanceltype" .
.B "pthread_setcanceltype"
ϡƤӽФåɤμä׵Фȿηѹ롣
ϡƱ(¨)ޤٱΤ줫Ǥ롣
.I "type"
ϡʼäǤꡢä׵᤬Ϥľ˸ƤӽФ
åɤä
.B "PTHREAD_CANCEL_ASYNCHRONOUS"
ä׵򼡤μäݥȤޤαݤ
.B "PTHREAD_CANCEL_DEFERRED"
Τ줫Ǥ롣
.I "oldtype"

.BR "NULL"
ǤʤСμä
.IR "oldtype"
λؤ˳Ǽ졢äơ夫̤
.BR "pthread_setcanceltype"
θƤӽФˤäƲ뤳ȤǽǤ롣

.\" Threads are always created by 
.\" .BR "pthread_create" (3)
.\" with cancellation
.\" enabled and deferred. That is, the initial cancellation state is
.\" .B "PTHREAD_CANCEL_ENABLE"
.\" and the initial type is
.\" .BR "PTHREAD_CANCEL_DEFERRED" .
åɤϾ
.BR "pthread_create" (3)
ˤäơäǽٱǺ롣
ʤμä֤
.B "PTHREAD_CANCEL_ENABLE"
Ǥꡢη
.BR "PTHREAD_CANCEL_DEFERRED"
Ǥ롣

.\" Cancellation points are those points in the program execution where a
.\" test for pending cancellation requests is performed and cancellation
.\" is executed if positive. The following POSIX threads functions
.\" are cancellation points:
äݥȤȤϡαμä׵ФƥȤԤ졢
ºݤ׵᤬мä¹ԤǤ롣ʲ POSIX å
ؿϼäݥȤǤ:

.\" .BR "pthread_join" (3)
.\" .br
.\" .BR "pthread_cond_wait" (3)
.\" .br
.\" .BR "pthread_cond_timedwait" (3)
.\" .br
.\" .BR "pthread_testcancel" (3)
.\" .br
.\" .BR "sem_wait" (3)
.\" .br
.\" .BR "sigwait" (3)
.BR "pthread_join" (3)
.br
.BR "pthread_cond_wait" (3)
.br
.BR "pthread_cond_timedwait" (3)
.br
.BR "pthread_testcancel" (3)
.br
.BR "sem_wait" (3)
.br
.BR "sigwait" (3)

.\" All other POSIX threads functions are guaranteed not to be
.\" cancellation points. That is, they never perform cancellation in
.\" deferred cancellation mode.
ʳƤ POSIX åɴؿϼäݥȤǤϤʤȤݾ
Ƥ롣ʤٱä⡼ɤǷ褷Ƽä
¸뤳ȤϤʤ

.\" .B "pthread_testcancel"
.\" does nothing except testing for pending
.\" cancellation and executing it. Its purpose is to introduce explicit
.\" checks for cancellation in long sequences of code that do not call
.\" cancellation point functions otherwise.
.B "pthread_testcancel"
αμä׵Ĵ١¸Ǥ롣Ūϡ
¾˼äݥȤȤʤؿƤӽФȤΤʤĹϢ³
ɤˡŪ˼äΥåƳ뤳ȤǤ롣

.\" .SH "RETURN VALUE"
.\"
.\" .BR "pthread_cancel" ,
.\" .B "pthread_setcancelstate"
.\" and
.\" .B "pthread_setcanceltype"
.\" return 0 on success and a non-zero error code
.\" on error.
.SH ֤

.BR "pthread_cancel"
.B "pthread_setcancelstate"

.B "pthread_setcanceltype"
 0 ֤顼ʤС󥼥Υ顼ɤ֤

.\" .SH ERRORS
.\"
.\" .B "pthread_cancel"
.\" returns the following error code on error:
.\" .RS
.\" .TP
.\" .B "ESRCH"
.\" no thread could be found corresponding to that specified by the 
.\" .I "thread"
.\" ID.
.\" .RE
.SH 顼
.B "pthread_cancel"
ϥ顼κݤ˼Υ顼ɤ֤:
.RS
.TP
.B "ESRCH"
.I "thread"
ǻꤵ줿Τб륹åɤ¸ߤʤ
ID.
.RE

.\" .B "pthread_setcancelstate"
.\" returns the following error code on error:
.\" .RS
.\" .TP
.\" .B "EINVAL"
.\" the 
.\" .I "state"
.\" argument is not 
.\" .B "PTHREAD_CANCEL_ENABLE"
.\" nor
.\" .B "PTHREAD_CANCEL_DISABLE"
.\" .RE
.B "pthread_setcancelstate"
ϥ顼κݤ˼Υ顼ɤ֤:
.RS
.TP
.B "EINVAL"
.I "state"

.B "PTHREAD_CANCEL_ENABLE"
Ǥ
.B "PTHREAD_CANCEL_DISABLE"
Ǥʤ
.RE

.\" .B "pthread_setcanceltype"
.\" returns the following error code on error:
.\" .RS
.\" .TP
.\" .B "EINVAL"
.\" the 
.\" .I "type"
.\" argument is not 
.\" .B "PTHREAD_CANCEL_DEFERRED"
.\" nor
.\" .B "PTHREAD_CANCEL_ASYNCHRONOUS"
.\" .RE
.B "pthread_setcanceltype"
ϥ顼κݤ˼Υ顼ɤ֤:
.RS
.TP
.B "EINVAL"
.I "type"

.B "PTHREAD_CANCEL_DEFERRED"
Ǥ
.B "PTHREAD_CANCEL_ASYNCHRONOUS"
Ǥʤ
.RE

.\" .SH AUTHOR
.\" Xavier Leroy <Xavier.Leroy@inria.fr>
.\"
.\" .SH "SEE ALSO"
.\" .BR "pthread_exit" (3),
.\" .BR "pthread_cleanup_push" (3),
.\" .BR "pthread_cleanup_pop" (3).
.SH 
Xavier Leroy <Xavier.Leroy@inria.fr>

.SH Ϣ
.BR "pthread_exit" (3),
.BR "pthread_cleanup_push" (3),
.BR "pthread_cleanup_pop" (3).

.\".SH BUGS
.SH Х

.\" POSIX specifies that a number of system calls (basically, all
.\" system calls that may block, such as 
.\" .BR "read" (2),
.\" .BR "write" (2),
.\" .BR "wait" (2),
.\" etc.) and library functions that may call these system calls (e.g.
.\" .BR "fprintf" (3))
.\" are cancellation points.  LinuxThreads is not yet
.\" integrated enough with the C library to implement this, and thus none
.\" of the C library functions is a cancellation point.
POSIX ϰϢΥƥॳ(Ūˤ
.BR "read" (2),
.BR "write" (2),
.BR "wait" (2),
Τ褦ʥ֥åβǽΤƤδؿ)ȤΥƥॳ
Ƥ֤褦ʥ饤֥ؿ(㤨
.BR "fprintf" (3))
äݥȤǤȵꤷƤ롣 LinuxThreads Ϥ
ˤϡޤʬ C 饤֥礵Ƥȸ
äƤʤ C 饤֥δؿäݥȤǤϤʤ

.\" For system calls at least, there is a workaround. Cancellation
.\" requests are transmitted to the target thread by sending it a
.\" signal. That signal will interrupt all blocking system calls, causing
.\" them to return immediately with the 
.\" .B "EINTR"
.\" error. So, checking for
.\" cancellation during a 
.\" .B "read"
.\" system call, for instance, can be
.\" achieved as follows:
ʤȤ⡢ƥॳФƤϤ򤹤ˡ롣
ä׵ϡɸåɤ˥ʥ뤳Ȥˤä롣
Υʥϥ֥åƤ륷ƥॳƤФƳߤݤ
ľ
.B "EINTR"
롣äơ㤨
.B "read"
ƥॳƤǤ֤˼äåˤϡΤ褦
ɤ:

.RS
.ft 3
.nf
.sp
pthread_testcancel();
retcode = read(fd, buffer, length);
pthread_testcancel();
.ft
.LP
.RE
.fi


[] εҤ glibc2 ѤƥǤʤʲ 
glib-2.1.2  info ե뤫ΰѤǤ롣

.\"    Cancellation points are the points where the thread checks for
.\" pending cancellation requests and performs them.  The POSIX threads
.\" functions `pthread_join', `pthread_cond_wait',
.\" `pthread_cond_timedwait', `pthread_testcancel', `sem_wait', and
.\" `sigwait' are cancellation points.  In addition, these system calls are
.\" cancellation points:
.\"
.\" accept                   open                     sendmsg                  
.\" close                    pause                    sendto                   
.\" connect                  read                     system                   
.\" fcntl                    recv                     tcdrain                  
.\" fsync                    recvfrom                 wait                     
.\" lseek                    recvmsg                  waitpid                  
.\" msync                    send                     write                    
.\" nanosleep                                                                  
.\"
.\" All library functions that call these functions (such as `printf') are
.\"also cancellation points.
äݥȤȤϡαμä׵ФƥȤԤ졢
ºݤ׵᤬мä¹ԤǤ롣POSIX åɴؿ
Τ`pthread_join', `pthread_cond_wait', `pthread_cond_timed_wait', 
`pthread_testcancel', `sem_wait' ڤ `sigwait' ϼäݥ
Ǥ롣 ˲äơʲΥƥॳϼäݥȤǤ:

 accept                   open                     sendmsg                  
 close                    pause                    sendto                   
 connect                  read                     system                   
 fcntl                    recv                     tcdrain                  
 fsync                    recvfrom                 wait                     
 lseek                    recvmsg                  waitpid                  
 msync                    send                     write                    
 nanosleep                                                                  

δؿƤӽФǽΤ printf() ʤɤΥ饤֥ؿ
äݥȤˤʤ礬롣