File: pthread_cancel.3

package info (click to toggle)
manpages-ja 0.5.0.0.20180315%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 28,516 kB
  • sloc: perl: 161; makefile: 101
file content (443 lines) | stat: -rw-r--r-- 15,616 bytes parent folder | download | duplicates (6)
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() などのライブラリ関数も
取り消しポイントになる場合がある。