1PTHREAD_SETCANCELSTATE(3P) POSIX Programmer's ManualPTHREAD_SETCANCELSTATE(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       pthread_setcancelstate, pthread_setcanceltype, pthread_testcancel — set
14       cancelability state
15

SYNOPSIS

17       #include <pthread.h>
18
19       int pthread_setcancelstate(int state, int *oldstate);
20       int pthread_setcanceltype(int type, int *oldtype);
21       void pthread_testcancel(void);
22

DESCRIPTION

24       The  pthread_setcancelstate()  function  shall  atomically both set the
25       calling thread's cancelability state to the indicated state and  return
26       the  previous  cancelability  state  at the location referenced by old‐
27       state.   Legal  values  for   state   are   PTHREAD_CANCEL_ENABLE   and
28       PTHREAD_CANCEL_DISABLE.
29
30       The  pthread_setcanceltype()  function  shall  atomically  both set the
31       calling thread's cancelability type to the indicated  type  and  return
32       the  previous cancelability type at the location referenced by oldtype.
33       Legal values for  type  are  PTHREAD_CANCEL_DEFERRED  and  PTHREAD_CAN‐
34       CEL_ASYNCHRONOUS.
35
36       The  cancelability state and type of any newly created threads, includ‐
37       ing the thread in which main() was first invoked, shall be PTHREAD_CAN‐
38       CEL_ENABLE and PTHREAD_CANCEL_DEFERRED respectively.
39
40       The  pthread_testcancel() function shall create a cancellation point in
41       the calling thread. The pthread_testcancel()  function  shall  have  no
42       effect if cancelability is disabled.
43

RETURN VALUE

45       If successful, the pthread_setcancelstate() and pthread_setcanceltype()
46       functions shall return  zero;  otherwise,  an  error  number  shall  be
47       returned to indicate the error.
48

ERRORS

50       The pthread_setcancelstate() function may fail if:
51
52       EINVAL The specified state is not PTHREAD_CANCEL_ENABLE or PTHREAD_CAN‐
53              CEL_DISABLE.
54
55       The pthread_setcanceltype() function may fail if:
56
57       EINVAL The   specified   type   is   not   PTHREAD_CANCEL_DEFERRED   or
58              PTHREAD_CANCEL_ASYNCHRONOUS.
59
60       These functions shall not return an error code of [EINTR].
61
62       The following sections are informative.
63

EXAMPLES

65       None.
66

APPLICATION USAGE

68       None.
69

RATIONALE

71       The pthread_setcancelstate() and pthread_setcanceltype() functions con‐
72       trol the points at which a thread may be asynchronously  canceled.  For
73       cancellation  control  to be usable in modular fashion, some rules need
74       to be followed.
75
76       An object can be considered to be a generalization of a  procedure.  It
77       is  a  set  of  procedures  and  global variables written as a unit and
78       called by clients not known by the object. Objects may depend on  other
79       objects.
80
81       First,  cancelability  should  only  be disabled on entry to an object,
82       never explicitly enabled. On exit from  an  object,  the  cancelability
83       state should always be restored to its value on entry to the object.
84
85       This follows from a modularity argument: if the client of an object (or
86       the client of an object that uses that object) has disabled cancelabil‐
87       ity,  it  is  because  the  client  does not want to be concerned about
88       cleaning up if the thread is canceled while executing some sequence  of
89       actions. If an object is called in such a state and it enables cancela‐
90       bility and a cancellation request is pending for that thread, then  the
91       thread is canceled, contrary to the wish of the client that disabled.
92
93       Second, the cancelability type may be explicitly set to either deferred
94       or asynchronous upon entry to an object. But as with the  cancelability
95       state,  on  exit from an object the cancelability type should always be
96       restored to its value on entry to the object.
97
98       Finally, only functions that are  cancel-safe  may  be  called  from  a
99       thread that is asynchronously cancelable.
100

FUTURE DIRECTIONS

102       None.
103

SEE ALSO

105       pthread_cancel()
106
107       The Base Definitions volume of POSIX.1‐2008, <pthread.h>
108
110       Portions  of  this text are reprinted and reproduced in electronic form
111       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
112       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
113       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
114       cal  and  Electronics  Engineers,  Inc  and  The  Open Group.  (This is
115       POSIX.1-2008 with the 2013 Technical Corrigendum  1  applied.)  In  the
116       event of any discrepancy between this version and the original IEEE and
117       The Open Group Standard, the original IEEE and The Open Group  Standard
118       is  the  referee document. The original Standard can be obtained online
119       at http://www.unix.org/online.html .
120
121       Any typographical or formatting errors that appear  in  this  page  are
122       most likely to have been introduced during the conversion of the source
123       files to man page format. To report such errors,  see  https://www.ker
124       nel.org/doc/man-pages/reporting_bugs.html .
125
126
127
128IEEE/The Open Group                  2013           PTHREAD_SETCANCELSTATE(3P)
Impressum