1 .\" Copyright (C) 1994-1999 Free Software Foundation, Inc.
3 .\" Permission is granted to make and distribute verbatim copies of
4 .\" this manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of
8 .\" this manual under the conditions for verbatim copying, provided that
9 .\" the entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Permission is granted to copy and distribute translations of this
13 .\" manual into another language, under the above conditions for modified
14 .\" versions, except that this permission notice may be stated in a
15 .\" translation approved by the Foundation.
17 .\" Copyright (C) 1999 Xavier Leroy.
19 .\" Japanese Version Copyright (C) 2000 WAKABAYASHI, Takeyasu
20 .\" all rights reserved.
21 .\" Translated on Fri Jan 14 16:50:24 JST 2000
22 .\" by WAKABAYASHI, Takeyasu <twakaba@eco.toyama-u.ac.jp>
25 .\" .TH PTHREAD_CANCEL 3 LinuxThreads
29 .\" pthread_cancel, pthread_setcancelstate, pthread_setcanceltype, pthread_testcancel \- thread cancellation
32 .\" .B #include <pthread.h>
34 .\" .BI "int pthread_cancel(pthread_t " thread ");"
36 .\" .BI "int pthread_setcancelstate(int " state ", int *" oldstate ");"
38 .\" .BI "int pthread_setcanceltype(int " type ", int *" oldtype ");"
40 .\" .BI "void pthread_testcancel(void);"
41 .TH PTHREAD_CANCEL 3 LinuxThreads
45 pthread_cancel, pthread_setcancelstate, pthread_setcanceltype, pthread_testcancel \- ¥¹¥ì¥Ã¥É¤Î¼è¤ê¾Ã¤·
48 .B #include <pthread.h>
50 .BI "int pthread_cancel(pthread_t " thread ");"
52 .BI "int pthread_setcancelstate(int " state ", int *" oldstate ");"
54 .BI "int pthread_setcanceltype(int " type ", int *" oldtype ");"
56 .BI "void pthread_testcancel(void);"
60 .\" Cancellation is the mechanism by which a thread can terminate the
61 .\" execution of another thread. More precisely, a thread can send a
62 .\" cancellation request to another thread. Depending on its settings, the
63 .\" target thread can then either ignore the request, honor it
64 .\" immediately, or defer it till it reaches a cancellation point.
67 ¼è¤ê¾Ã¤·¤Ï¡¢¤¢¤ë¥¹¥ì¥Ã¥É¤¬Â¾¤Î¥¹¥ì¥Ã¥É¤Î¼Â¹Ô¤ò½ªÎ»¤µ¤»¤ë¤³¤È¤ò²Äǽ
68 ¤Ë¤¹¤ë¥á¥«¥Ë¥º¥à¤Ç¤¢¤ë¡£¤è¤êÀµ³Î¤Ë¤Ï¡¢¥¹¥ì¥Ã¥É¤Ï¾¤Î¥¹¥ì¥Ã¥É¤ËÂФ·¤Æ
69 ¼è¾ÃÍ×µá¤òÁ÷¤ë¤³¤È¤¬¤Ç¤¤ë¡£ÀßÄ꼡Âè¤Ç¡¢ÌÜɸ¤Î¥¹¥ì¥Ã¥É¤Ï¡¢Í×µá¤ò̵»ë
70 ¤·¤¿¤ê¡¢Ä¾¤Á¤Ë¼Â¸½¤·¤¿¤ê¡¢¤¢¤ë¼è¤ê¾Ã¤·¥Ý¥¤¥ó¥È¤Ë»ê¤ë¤Þ¤Ç¤½¤ÎÍ×µá¤Î¼Â¹Ô
73 .\" When a thread eventually honors a cancellation request, it performs as
75 .\" .B "pthread_exit(PTHREAD_CANCELED)"
76 .\" has been called at that point:
77 .\" all cleanup handlers are executed in reverse order, finalization
78 .\" functions for thread-specific data are called, and finally the thread
79 .\" stops executing with the return value
80 .\" .BR "PTHREAD_CANCELED" .
82 .\" .BR "pthread_exit" (3)
83 .\" for more information.
84 ¥¹¥ì¥Ã¥É¤¬ºÇ½ªÅª¤Ë¼è¤ê¾Ã¤·Í×µá¤ò¼Â¸½¤¹¤ëºÝ¤Ë¤Ï¡¢¤½¤ì¤Ï¤¢¤¿¤«¤â
85 .B "pthread_exit(PTHREAD_CANCELED)"
86 ¤¬¤½¤Î»þÅÀ¤Ç¸Æ¤Ó½Ð¤µ¤ì¤¿¤«¤Î¤è¤¦¤Ë¿¶Éñ¤¦¡£¤¹¤Ê¤ï¤Á¡¢Á´¤Æ¤Î¥¯¥ê¡¼¥ó
87 ¥¢¥Ã¥×¥Ï¥ó¥É¥é¤¬µÕ½ç¤Ë¼Â¹Ô¤µ¤ì¡¢¥¹¥ì¥Ã¥É¸Çͥǡ¼¥¿¤Î½ªÎ»½èÍý´Ø¿ô¤¬
88 ¸Æ¤Ó½Ð¤µ¤ì¡¢ºÇ¸å¤Ë¥¹¥ì¥Ã¥É¤Ï¡¢ÊÖ¤êÃÍ
90 ¤Ç¼Â¹Ô¤òÄä»ß¤¹¤ë¡£¾Ü¤·¤¯¤Ï
91 .BR "pthread_exit" (3)
94 .\" .B "pthread_cancel"
95 .\" sends a cancellation request to the thread denoted
102 °ú¿ô¤Ç»ØÄꤵ¤ì¤¿¥¹¥ì¥Ã¥É¤ËÂФ·¤Æ¡¢¼è¤ê¾Ã¤·Í×µá¤òÁ÷¤ë¡£
104 .\" .B "pthread_setcancelstate"
105 .\" changes the cancellation state for the
106 .\" calling thread -- that is, whether cancellation requests are ignored
109 .\" argument is the new cancellation state: either
110 .\" .B "PTHREAD_CANCEL_ENABLE"
111 .\" to enable cancellation, or
112 .\" .B "PTHREAD_CANCEL_DISABLE"
113 .\" to disable cancellation (cancellation
114 .\" requests are ignored). If
119 .\" cancellation state is stored in the location pointed to by
121 .\" and can thus be restored later by another call to
122 .\" .BR "pthread_setcancelstate" .
123 .B "pthread_setcancelstate"
124 ¤Ï¡¢¤³¤ì¤ò¸Æ¤Ó½Ð¤¹¥¹¥ì¥Ã¥É¤Î¼è¤ê¾Ã¤·¾õÂÖ¤òÊѹ¹¤¹¤ë¡£
125 ¤¹¤Ê¤ï¤Á¡¢¼è¤ê¾Ã¤·Í×µá¤ò¼õ¤±Æþ¤ì¤ë¤«Èݤ«¤òÊѹ¹¤¹¤ë¡£
127 °ú¿ô¤Ï¿·¤¿¤Ê¼è¤ê¾Ã¤·¾õÂ֤Ǥ¢¤ë¡£¤³¤ì¤Ï¼è¤ê¾Ã¤·¤ò²Äǽ¤Ë¤¹¤ë
128 .B "PTHREAD_CANCEL_ENABLE"
129 ¤â¤·¤¯¤Ï¡¢¼è¤ê¾Ã¤·¤òÉÔ²Äǽ¤Ë¤¹¤ë(¼è¤ê¾Ã¤·Í×µá¤ò̵»ë¤¹¤ë)
130 .B "PTHREAD_CANCEL_DISABLE"
135 ¤Ç¤Ê¤±¤ì¤Ð¡¢°ÊÁ°¤Î¼è¤ê¾Ã¤·¾õÂÖ¤¬
137 ¤¬»Ø¤¹¾ì½ê¤Ë³ÊǼ¤µ¤ì¡¢½¾¤Ã¤Æ¡¢¸å¤ÇÊ̤Î
138 .BR "pthread_setcancelstate"
139 ¤Î¸Æ¤Ó½Ð¤·¤Ë¤è¤ê¡¢²óÉü¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
141 .\" .B "pthread_setcanceltype"
142 .\" changes the type of responses to cancellation
143 .\" requests for the calling thread: asynchronous (immediate) or deferred.
146 .\" argument is the new cancellation type: either
147 .\" .B "PTHREAD_CANCEL_ASYNCHRONOUS"
148 .\" to cancel the calling thread as soon as
149 .\" the cancellation request is received, or
150 .\" .B "PTHREAD_CANCEL_DEFERRED"
152 .\" keep the cancellation request pending until the next cancellation
158 .\" cancellation state is stored in the location pointed to by
160 .\" and can thus be restored later by another call to
161 .\" .BR "pthread_setcanceltype" .
162 .B "pthread_setcanceltype"
163 ¤Ï¡¢¤³¤ì¤ò¸Æ¤Ó½Ð¤¹¥¹¥ì¥Ã¥É¤Î¼è¤ê¾Ã¤·Í×µá¤ËÂФ¹¤ëÈ¿±þ¤Î·¿¤òÊѹ¹¤¹¤ë¡£
164 ¤³¤ì¤Ï¡¢ÈóƱ´ü(¨»þ)¤Þ¤¿¤ÏÃÙ±ä¤Î¤¤¤º¤ì¤«¤Ç¤¢¤ë¡£
166 °ú¿ô¤Ï¡¢¿·¤¿¤Ê¼è¤ê¾Ã¤·Êý¤Ç¤¢¤ê¡¢¼è¤ê¾Ã¤·Í׵᤬ÆϤ¯¤Èľ¤Á¤Ë¸Æ¤Ó½Ð¤·
168 .B "PTHREAD_CANCEL_ASYNCHRONOUS"
169 ¤«¡¢¼è¤ê¾Ã¤·Í×µá¤ò¼¡¤Î¼è¤ê¾Ã¤·¥Ý¥¤¥ó¥È¤Þ¤ÇαÊݤ¹¤ë
170 .B "PTHREAD_CANCEL_DEFERRED"
175 ¤Ç¤Ê¤±¤ì¤Ð¡¢°ÊÁ°¤Î¼è¤ê¾Ã¤··¿¤¬
177 ¤Î»Ø¤¹¾ì½ê¤Ë³ÊǼ¤µ¤ì¡¢½¾¤Ã¤Æ¡¢¸å¤«¤éÊ̤Î
178 .BR "pthread_setcanceltype"
179 ¤Î¸Æ¤Ó½Ð¤·¤Ë¤è¤Ã¤Æ²óÉü¤¹¤ë¤³¤È¤¬²Äǽ¤Ç¤¢¤ë¡£
181 .\" Threads are always created by
182 .\" .BR "pthread_create" (3)
183 .\" with cancellation
184 .\" enabled and deferred. That is, the initial cancellation state is
185 .\" .B "PTHREAD_CANCEL_ENABLE"
186 .\" and the initial type is
187 .\" .BR "PTHREAD_CANCEL_DEFERRED" .
189 .BR "pthread_create" (3)
190 ¤Ë¤è¤Ã¤Æ¡¢¼è¤ê¾Ã¤·²Äǽ¤«¤ÄÃÙ±ä¤ÇºîÀ®¤µ¤ì¤ë¡£
191 ¤¹¤Ê¤ï¤Á¡¢½é´ü¤Î¼è¤ê¾Ã¤·¾õÂÖ¤Ï
192 .B "PTHREAD_CANCEL_ENABLE"
194 .BR "PTHREAD_CANCEL_DEFERRED"
197 .\" Cancellation points are those points in the program execution where a
198 .\" test for pending cancellation requests is performed and cancellation
199 .\" is executed if positive. The following POSIX threads functions
200 .\" are cancellation points:
201 ¼è¤ê¾Ã¤·¥Ý¥¤¥ó¥È¤È¤Ï¡¢ÊÝαÃæ¤Î¼è¤ê¾Ã¤·Í×µá¤ËÂФ¹¤ë¥Æ¥¹¥È¤¬¹Ô¤ï¤ì¡¢
202 ¼ÂºÝ¤ËÍ׵᤬¤¢¤ì¤Ð¼è¤ê¾Ã¤·¤¬¼Â¹Ô¤µ¤ì¤ëÅÀ¤Ç¤¢¤ë¡£°Ê²¼¤Î POSIX ¥¹¥ì¥Ã¥É
203 ´Ø¿ô¤Ï¼è¤ê¾Ã¤·¥Ý¥¤¥ó¥È¤Ç¤¢¤ë:
205 .\" .BR "pthread_join" (3)
207 .\" .BR "pthread_cond_wait" (3)
209 .\" .BR "pthread_cond_timedwait" (3)
211 .\" .BR "pthread_testcancel" (3)
213 .\" .BR "sem_wait" (3)
215 .\" .BR "sigwait" (3)
216 .BR "pthread_join" (3)
218 .BR "pthread_cond_wait" (3)
220 .BR "pthread_cond_timedwait" (3)
222 .BR "pthread_testcancel" (3)
228 .\" All other POSIX threads functions are guaranteed not to be
229 .\" cancellation points. That is, they never perform cancellation in
230 .\" deferred cancellation mode.
231 ¤³¤ì°Ê³°¤ÎÁ´¤Æ¤Î POSIX ¥¹¥ì¥Ã¥É´Ø¿ô¤Ï¼è¤ê¾Ã¤·¥Ý¥¤¥ó¥È¤Ç¤Ï¤Ê¤¤¤³¤È¤¬ÊݾÚ
232 ¤µ¤ì¤Æ¤¤¤ë¡£¤¹¤Ê¤ï¤Á¡¢¤½¤ì¤é¤ÏÃÙ±ä¼è¤ê¾Ã¤·¥â¡¼¥É¤Ç·è¤·¤Æ¼è¤ê¾Ã¤·¤ò
235 .\" .B "pthread_testcancel"
236 .\" does nothing except testing for pending
237 .\" cancellation and executing it. Its purpose is to introduce explicit
238 .\" checks for cancellation in long sequences of code that do not call
239 .\" cancellation point functions otherwise.
240 .B "pthread_testcancel"
241 ¤ÏÊÝαÃæ¤Î¼è¤ê¾Ã¤·Í×µá¤òÄ´¤Ù¡¢¤½¤ì¤ò¼Â¸½¤¹¤ë¤À¤±¤Ç¤¢¤ë¡£¤½¤ÎÌÜŪ¤Ï¡¢
242 ¾¤Ë¼è¤ê¾Ã¤·¥Ý¥¤¥ó¥È¤È¤Ê¤ë´Ø¿ô¤ò¸Æ¤Ó½Ð¤¹¤³¤È¤Î¤Ê¤¤¡¢Ä¹¤¤Ï¢Â³¤·¤¿
243 ¥³¡¼¥É¤ÎÃæ¤Ë¡¢ÌÀ¼¨Åª¤Ë¼è¤ê¾Ã¤·¤Î¥Á¥§¥Ã¥¯¤òƳÆþ¤¹¤ë¤³¤È¤Ç¤¢¤ë¡£
245 .\" .SH "RETURN VALUE"
247 .\" .BR "pthread_cancel" ,
248 .\" .B "pthread_setcancelstate"
250 .\" .B "pthread_setcanceltype"
251 .\" return 0 on success and a non-zero error code
255 .BR "pthread_cancel"¡¢
256 .B "pthread_setcancelstate"
258 .B "pthread_setcanceltype"
259 ¤ÏÀ®¸ù¤¹¤ë¤È 0 ¤òÊÖ¤·¡¢¥¨¥é¡¼¤Ê¤é¤Ð¡¢Èó¥¼¥í¤Î¥¨¥é¡¼¥³¡¼¥É¤òÊÖ¤¹¡£
263 .\" .B "pthread_cancel"
264 .\" returns the following error code on error:
268 .\" no thread could be found corresponding to that specified by the
274 ¤Ï¥¨¥é¡¼¤ÎºÝ¤Ë¼¡¤Î¥¨¥é¡¼¥³¡¼¥É¤òÊÖ¤¹:
279 ¤Ç»ØÄꤵ¤ì¤¿¤â¤Î¤ËÂбþ¤¹¤ë¥¹¥ì¥Ã¥É¤¬Â¸ºß¤·¤Ê¤¤¡£
283 .\" .B "pthread_setcancelstate"
284 .\" returns the following error code on error:
291 .\" .B "PTHREAD_CANCEL_ENABLE"
293 .\" .B "PTHREAD_CANCEL_DISABLE"
295 .B "pthread_setcancelstate"
296 ¤Ï¥¨¥é¡¼¤ÎºÝ¤Ë¼¡¤Î¥¨¥é¡¼¥³¡¼¥É¤òÊÖ¤¹:
302 .B "PTHREAD_CANCEL_ENABLE"
304 .B "PTHREAD_CANCEL_DISABLE"
308 .\" .B "pthread_setcanceltype"
309 .\" returns the following error code on error:
316 .\" .B "PTHREAD_CANCEL_DEFERRED"
318 .\" .B "PTHREAD_CANCEL_ASYNCHRONOUS"
320 .B "pthread_setcanceltype"
321 ¤Ï¥¨¥é¡¼¤ÎºÝ¤Ë¼¡¤Î¥¨¥é¡¼¥³¡¼¥É¤òÊÖ¤¹:
327 .B "PTHREAD_CANCEL_DEFERRED"
329 .B "PTHREAD_CANCEL_ASYNCHRONOUS"
334 .\" Xavier Leroy <Xavier.Leroy@inria.fr>
337 .\" .BR "pthread_exit" (3),
338 .\" .BR "pthread_cleanup_push" (3),
339 .\" .BR "pthread_cleanup_pop" (3).
341 Xavier Leroy <Xavier.Leroy@inria.fr>
344 .BR "pthread_exit" (3),
345 .BR "pthread_cleanup_push" (3),
346 .BR "pthread_cleanup_pop" (3).
351 .\" POSIX specifies that a number of system calls (basically, all
352 .\" system calls that may block, such as
356 .\" etc.) and library functions that may call these system calls (e.g.
357 .\" .BR "fprintf" (3))
358 .\" are cancellation points. LinuxThreads is not yet
359 .\" integrated enough with the C library to implement this, and thus none
360 .\" of the C library functions is a cancellation point.
361 POSIX ¤Ï°ìÏ¢¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë(´ðËÜŪ¤Ë¤Ï
365 Åù¤Î¤è¤¦¤Ê¥Ö¥í¥Ã¥¯¤Î²ÄǽÀ¤Î¤¢¤ëÁ´¤Æ¤Î´Ø¿ô)¤È¤½¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë
366 ¤ò¸Æ¤Ö¤è¤¦¤Ê¥é¥¤¥Ö¥é¥ê´Ø¿ô(Î㤨¤Ð
368 ¤¬¼è¤ê¾Ã¤·¥Ý¥¤¥ó¥È¤Ç¤¢¤ë¤Èµ¬Äꤷ¤Æ¤¤¤ë¡£ LinuxThreads ¤Ï¤³¤ì¤ò¼ÂÁõ¤¹¤ë
369 ¤Ë¤Ï¡¢¤Þ¤À½½Ê¬¤Ë C ¥é¥¤¥Ö¥é¥ê¤ÈÅý¹ç¤µ¤ì¤Æ¤¤¤ë¤È¸À¤¨¤º¡¢
370 ½¾¤Ã¤Æ¤¤¤«¤Ê¤ë C ¥é¥¤¥Ö¥é¥ê¤Î´Ø¿ô¤â¼è¤ê¾Ã¤·¥Ý¥¤¥ó¥È¤Ç¤Ï¤Ê¤¤¡£
372 .\" For system calls at least, there is a workaround. Cancellation
373 .\" requests are transmitted to the target thread by sending it a
374 .\" signal. That signal will interrupt all blocking system calls, causing
375 .\" them to return immediately with the
377 .\" error. So, checking for
378 .\" cancellation during a
380 .\" system call, for instance, can be
381 .\" achieved as follows:
382 ¾¯¤Ê¤¯¤È¤â¡¢¥·¥¹¥Æ¥à¥³¡¼¥ë¤ËÂФ·¤Æ¤Ï¤³¤ì¤ò²óÈò¤¹¤ëÊýË¡¤¬¤¢¤ë¡£
383 ¼è¤ê¾Ã¤·Í×µá¤Ï¡¢ÌÜɸ¥¹¥ì¥Ã¥É¤Ë¥·¥°¥Ê¥ë¤òÁ÷¤ë¤³¤È¤Ë¤è¤Ã¤ÆÁ÷¿®¤µ¤ì¤ë¡£
384 ¤³¤Î¥·¥°¥Ê¥ë¤Ï¥Ö¥í¥Ã¥¯¤·¤Æ¤¤¤ë¥·¥¹¥Æ¥à¥³¡¼¥ëÁ´¤Æ¤ËÂФ·¤Æ³ä¹þ¤ß¤ò³Ý¤±¡¢
387 ¤ÇÌá¤ë¡£¤è¤Ã¤Æ¡¢Î㤨¤Ð
389 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤ò¸Æ¤ó¤Ç¤¤¤ë´Ö¤Ë¼è¤ê¾Ã¤·¤ò¥Á¥§¥Ã¥¯¤¹¤ë¤Ë¤Ï¡¢¼¡¤Î¤è¤¦¤Ë
396 pthread_testcancel();
397 retcode = read(fd, buffer, length);
398 pthread_testcancel();
405 [ÌõÃí] ¾å¤Îµ½Ò¤Ï glibc2 ¤òÍѤ¤¤¿¥·¥¹¥Æ¥à¤Ç¤ÏÀµ¤·¤¯¤Ê¤¤¡£°Ê²¼¤Ï
406 glib-2.1.2 ¤Î info ¥Õ¥¡¥¤¥ë¤«¤é¤Î°úÍѤǤ¢¤ë¡£
408 .\" Cancellation points are the points where the thread checks for
409 .\" pending cancellation requests and performs them. The POSIX threads
410 .\" functions `pthread_join', `pthread_cond_wait',
411 .\" `pthread_cond_timedwait', `pthread_testcancel', `sem_wait', and
412 .\" `sigwait' are cancellation points. In addition, these system calls are
413 .\" cancellation points:
415 .\" accept open sendmsg
416 .\" close pause sendto
417 .\" connect read system
418 .\" fcntl recv tcdrain
419 .\" fsync recvfrom wait
420 .\" lseek recvmsg waitpid
424 .\" All library functions that call these functions (such as `printf') are
425 .\"also cancellation points.
426 ¼è¤ê¾Ã¤·¥Ý¥¤¥ó¥È¤È¤Ï¡¢ÊÝαÃæ¤Î¼è¤ê¾Ã¤·Í×µá¤ËÂФ¹¤ë¥Æ¥¹¥È¤¬¹Ô¤ï¤ì¡¢
427 ¼ÂºÝ¤ËÍ׵᤬¤¢¤ì¤Ð¼è¤ê¾Ã¤·¤¬¼Â¹Ô¤µ¤ì¤ëÅÀ¤Ç¤¢¤ë¡£POSIX ¥¹¥ì¥Ã¥É´Ø¿ô
428 ¤Î¤¦¤Á¡¢`pthread_join', `pthread_cond_wait', `pthread_cond_timed_wait',
429 `pthread_testcancel', `sem_wait' µÚ¤Ó `sigwait' ¤Ï¼è¤ê¾Ã¤·¥Ý¥¤¥ó¥È
430 ¤Ç¤¢¤ë¡£ ¤³¤ì¤Ë²Ã¤¨¤Æ¡¢°Ê²¼¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¼è¤ê¾Ã¤·¥Ý¥¤¥ó¥È¤Ç¤¢¤ë:
437 lseek recvmsg waitpid
441 ¤³¤ì¤é¤Î´Ø¿ô¤ò¸Æ¤Ó½Ð¤¹²ÄǽÀ¤Î¤¢¤ë printf() ¤Ê¤É¤Î¥é¥¤¥Ö¥é¥ê´Ø¿ô¤â
442 ¼è¤ê¾Ã¤·¥Ý¥¤¥ó¥È¤Ë¤Ê¤ë¾ì¹ç¤¬¤¢¤ë¡£