Print this page
9842 man page typos and spelling

Split Close
Expand all
Collapse all
          --- old/usr/src/man/man5/cancellation.5
          +++ new/usr/src/man/man5/cancellation.5
↓ open down ↓ 40 lines elided ↑ open up ↑
  41   41  .\"
  42   42  .\"
  43   43  .\" Portions Copyright (c) 1995 IEEE.  All Rights Reserved.
  44   44  .\" Copyright (c) 2001, The IEEE and The Open Group.  All Rights Reserved.
  45   45  .\" Copyright (c) 2008, Sun Microsystems, Inc.  All Rights Reserved.
  46   46  .\"
  47   47  .TH CANCELLATION 5 "Oct 4, 2005"
  48   48  .SH NAME
  49   49  cancellation \- overview of concepts related to POSIX thread cancellation
  50   50  .SH DESCRIPTION
  51      -.sp
  52      -
  53      -.sp
  54   51  .TS
  55   52  box;
  56   53  c | c
  57   54  l | l .
  58   55  FUNCTION        ACTION
  59   56  _
  60   57  \fBpthread_cancel()\fR  Cancels thread execution.
  61   58  \fBpthread_setcancelstate()\fR  Sets the cancellation \fIstate\fR of a thread.
  62   59  \fBpthread_setcanceltype()\fR   Sets the cancellation \fItype\fR of a thread.
  63   60  \fBpthread_testcancel()\fR      T{
  64   61  Creates a cancellation point in the calling thread.
  65   62  T}
  66   63  \fBpthread_cleanup_push()\fR    Pushes a cleanup handler routine.
  67   64  \fBpthread_cleanup_pop()\fR     Pops a cleanup handler routine.
  68   65  .TE
  69   66  
  70   67  .SS "Cancellation"
  71      -.sp
  72   68  .LP
  73   69  Thread cancellation allows a thread to terminate the execution of  any
  74   70  application thread in the process. Cancellation is useful when further
  75   71  operations of one or more threads are undesirable or unnecessary.
  76   72  .sp
  77   73  .LP
  78   74  An example of a situation that could benefit from using cancellation is an
  79   75  asynchronously-generated cancel condition such as a user requesting to close or
  80   76  exit some running operation. Another example is the completion of a task
  81   77  undertaken by a number of threads, such as solving a maze. While many threads
  82   78  search for the solution, one of the threads might solve the puzzle while the
  83   79  others continue to operate. Since they are serving no purpose at that point,
  84   80  they should all be canceled.
  85   81  .SS "Planning Steps"
  86      -.sp
  87   82  .LP
  88   83  Planning and programming for most cancellations follow this pattern:
  89   84  .RS +4
  90   85  .TP
  91   86  1.
  92   87  Identify which threads you want to cancel, and insert
  93   88  \fBpthread_cancel\fR(3C) statements.
  94   89  .RE
  95   90  .RS +4
  96   91  .TP
↓ open down ↓ 23 lines elided ↑ open up ↑
 120  115  .RS +4
 121  116  .TP
 122  117  5.
 123  118  To cancel a thread in a procedure that contains no cancellation points,
 124  119  insert your own cancellation points with \fBpthread_testcancel\fR(3C). This
 125  120  function creates cancellation points by testing for pending cancellations and
 126  121  performing those cancellations if they are found. Push and pop cleanup handlers
 127  122  around the cancellation point, if necessary (see Step 3, above).
 128  123  .RE
 129  124  .SS "Cancellation Points"
 130      -.sp
 131  125  .LP
 132  126  The system defines certain points at which cancellation can occur (cancellation
 133  127  points), and you can create additional cancellation points in your application
 134  128  with \fBpthread_testcancel()\fR.
 135  129  .sp
 136  130  .LP
 137  131  The following cancellation points are  defined by the system (system-defined
 138  132  cancellation points): \fBcreat\fR(2), \fBaio_suspend\fR(3C), \fBclose\fR(2),
 139  133  \fBcreat\fR(2), \fBgetmsg\fR(2), \fBgetpmsg\fR(2), \fBlockf\fR(3C),
 140  134  \fBmq_receive\fR(3C), \fBmq_send\fR(3C), \fBmsgrcv\fR(2), \fBmsgsnd\fR(2),
↓ open down ↓ 34 lines elided ↑ open up ↑
 175  169  A mutex is explicitly not a cancellation point and should be held for only the
 176  170  minimal essential time.
 177  171  .sp
 178  172  .LP
 179  173  Most of the dangers in performing cancellations deal with properly restoring
 180  174  invariants and freeing shared resources. For example, a carelessly canceled
 181  175  thread might leave a mutex in a locked state, leading to a deadlock. Or it
 182  176  might leave a region of memory allocated with no way to identify it and
 183  177  therefore no way to free it.
 184  178  .SS "Cleanup Handlers"
 185      -.sp
 186  179  .LP
 187  180  When a thread is canceled, it should release resources and clean up the state
 188  181  that is shared with other threads. So, whenever a thread that might be canceled
 189  182  changes the state of the system or of the program, be sure to push a cleanup
 190  183  handler with \fBpthread_cleanup_push\fR(3C) before the cancellation point.
 191  184  .sp
 192  185  .LP
 193  186  When a thread is canceled, all the currently-stacked cleanup handlers are
 194  187  executed in last-in-first-out (LIFO) order. Each handler is run in the scope in
 195  188  which it was pushed. When the last cleanup handler returns, the thread-specific
↓ open down ↓ 14 lines elided ↑ open up ↑
 210  203  \fBpthread_cleanup_push()\fR macro can be thought to expand to a token list
 211  204  whose first token is '{' with \fBpthread_cleanup_pop()\fR expanding to a token
 212  205  list whose last token is the corresponding '}').
 213  206  .sp
 214  207  .LP
 215  208  The effect of the use of \fBreturn\fR, \fBbreak\fR, \fBcontinue\fR, and
 216  209  \fBgoto\fR to prematurely leave a code block described by a pair of
 217  210  \fBpthread_cleanup_push()\fR and \fBpthread_cleanup_pop()\fR function calls is
 218  211  undefined.
 219  212  .SS "Cancellation State"
 220      -.sp
 221  213  .LP
 222  214  Most programmers will use only the default cancellation state of
 223  215  \fBPTHREAD_CANCEL_ENABLE\fR, but can choose to change the state by using
 224  216  \fBpthread_setcancelstate\fR(3C), which determines whether a thread is
 225  217  cancelable at all. With the default \fIstate\fR of
 226  218  \fBPTHREAD_CANCEL_ENABLE\fR, cancellation is enabled and the thread is
 227  219  cancelable at points determined by its cancellation \fItype\fR. See
 228  220  \fBCancellation Type\fR.
 229  221  .sp
 230  222  .LP
 231  223  If the \fIstate\fR is \fBPTHREAD_CANCEL_DISABLE\fR, cancellation is disabled,
 232  224  the thread is not cancelable at any point, and all cancellation requests to it
 233  225  are held pending.
 234  226  .sp
 235  227  .LP
 236  228  You might want to disable cancellation before a call to a cancel-unsafe
 237  229  library, restoring the old cancel state when the call returns from the library.
 238  230  See  \fBCancel-Safe\fR for explanations of cancel safety.
 239  231  .SS "Cancellation Type"
 240      -.sp
 241  232  .LP
 242  233  A thread's cancellation \fBtype\fR is set with \fBpthread_setcanceltype\fR(3C),
 243  234  and determines whether the thread can be canceled anywhere in its execution or
 244  235  only at cancellation points.
 245  236  .sp
 246  237  .LP
 247  238  With the default \fItype\fR of  \fBPTHREAD_CANCEL_DEFERRED\fR, the thread is
 248  239  cancelable only at cancellation points, and then only when cancellation is
 249  240  enabled.
 250  241  .sp
↓ open down ↓ 17 lines elided ↑ open up ↑
 268  259          Enabled (Default)       Disabled
 269  260  _
 270  261  Deferred (Default)      T{
 271  262  Cancellation occurs when the target thread reaches a cancellation point and a cancel is pending. (Default)
 272  263  T}      T{
 273  264  All cancellation requests to the target thread are held pending.
 274  265  T}
 275  266  Asynchronous    T{
 276  267  Receipt of a \fBpthread_cancel()\fR call causes immediate cancellation.
 277  268  T}      T{
 278      -All cancellation requests to the target thread are held pending; as soon as cancellation is re-enabled, pending cancellations are executedimmediately.
      269 +All cancellation requests to the target thread are held pending; as
      270 +soon as cancellation is re-enabled, pending cancellations are executed
      271 +immediately.
 279  272  T}
 280  273  .TE
 281  274  
 282  275  .SS "Cancel-Safe"
 283      -.sp
 284  276  .LP
 285  277  With the arrival of POSIX cancellation, the Cancel-Safe level has been added to
 286  278  the list of MT-Safety levels. See \fBattributes\fR(5). An application or
 287  279  library is Cancel-Safe whenever it has arranged for cleanup handlers to restore
 288  280  system or program state wherever cancellation can occur. The application or
 289  281  library is specifically Deferred-Cancel-Safe when it is Cancel-Safe for threads
 290  282  whose cancellation type is \fBPTHREAD_CANCEL_DEFERRED\fR. See \fBCancellation
 291  283  State\fR. It is specifically Asynchronous-Cancel-Safe when it is Cancel-Safe
 292  284  for threads whose cancellation type is \fBPTHREAD_CANCEL_ASYNCHRONOUS\fR.
 293  285  .sp
 294  286  .LP
 295  287  It is easier to arrange for deferred cancel safety, as this requires system and
 296  288  program state protection only around cancellation points. In general, expect
 297  289  that most applications and libraries are not Asynchronous-Cancel-Safe.
 298  290  .SS "POSIX Threads Only"
 299      -.sp
 300  291  .LP
 301  292  The cancellation functions described in this manual page are available for
 302  293  POSIX threads, only (the Solaris threads interfaces do not provide cancellation
 303  294  functions).
 304  295  .SH EXAMPLES
 305  296  .LP
 306  297  \fBExample 1 \fRCancellation example
 307  298  .sp
 308  299  .LP
 309  300  The following short C++ example shows the pushing/popping of cancellation
↓ open down ↓ 97 lines elided ↑ open up ↑
 407  398  {
 408  399          pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
 409  400          pthread_create(NULL, NULL, thread2, (void *)pthread_self());
 410  401          thr_yield();
 411  402          printf("Returned from %s\en",f2(0));
 412  403  }
 413  404  .fi
 414  405  .in -2
 415  406  
 416  407  .SH ATTRIBUTES
 417      -.sp
 418  408  .LP
 419  409  See \fBattributes\fR(5) for descriptions of the following attributes:
 420  410  .sp
 421  411  
 422  412  .sp
 423  413  .TS
 424  414  box;
 425  415  c | c
 426  416  l | l .
 427  417  ATTRIBUTE TYPE  ATTRIBUTE VALUE
 428  418  _
 429  419  MT-Level        MT-Safe
 430  420  .TE
 431  421  
 432  422  .SH SEE ALSO
 433      -.sp
 434  423  .LP
 435  424  \fBread\fR(2), \fBsigwait\fR(2), \fBwrite\fR(2), \fBIntro\fR(3),
 436  425  \fBcondition\fR(5), \fBpthread_cleanup_pop\fR(3C),
 437  426  \fBpthread_cleanup_push\fR(3C), \fBpthread_exit\fR(3C), \fBpthread_join\fR(3C),
 438  427  \fBpthread_setcancelstate\fR(3C), \fBpthread_setcanceltype\fR(3C),
 439  428  \fBpthread_testcancel\fR(3C), \fBsetjmp\fR(3C), \fBattributes\fR(5),
 440  429  \fBstandards\fR(5)
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX