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

NAME

12       pthread_setcancelstate, pthread_setcanceltype, pthread_testcancel - set
13       cancelability state
14

SYNOPSIS

16       #include <pthread.h>
17
18       int pthread_setcancelstate(int state, int *oldstate);
19       int pthread_setcanceltype(int type, int *oldtype);
20       void pthread_testcancel(void);
21
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
56       The pthread_setcanceltype() function may fail if:
57
58       EINVAL The   specified   type   is   not   PTHREAD_CANCEL_DEFERRED   or
59              PTHREAD_CANCEL_ASYNCHRONOUS.
60
61
62       These functions shall not return an error code of [EINTR].
63
64       The following sections are informative.
65

EXAMPLES

67       None.
68

APPLICATION USAGE

70       None.
71

RATIONALE

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

FUTURE DIRECTIONS

104       None.
105

SEE ALSO

107       pthread_cancel(),  the Base Definitions volume of IEEE Std 1003.1-2001,
108       <pthread.h>
109
111       Portions of this text are reprinted and reproduced in  electronic  form
112       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
113       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
114       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
115       Electrical and Electronics Engineers, Inc and The Open  Group.  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.opengroup.org/unix/online.html .
120
121
122
123IEEE/The Open Group                  2003           PTHREAD_SETCANCELSTATE(3P)
Impressum