1PTHREAD_CANCEL(3P)         POSIX Programmer's Manual        PTHREAD_CANCEL(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_cancel — cancel execution of a thread
14

SYNOPSIS

16       #include <pthread.h>
17
18       int pthread_cancel(pthread_t thread);
19

DESCRIPTION

21       The pthread_cancel() function shall request that  thread  be  canceled.
22       The  target  thread's  cancelability state and type determines when the
23       cancellation takes effect. When the cancellation is acted on, the  can‐
24       cellation  cleanup  handlers  for thread shall be called. When the last
25       cancellation cleanup handler returns, the thread-specific data destruc‐
26       tor  functions  shall  be  called for thread.  When the last destructor
27       function returns, thread shall be terminated.
28
29       The cancellation processing  in  the  target  thread  shall  run  asyn‐
30       chronously   with   respect   to  the  calling  thread  returning  from
31       pthread_cancel().
32

RETURN VALUE

34       If successful, the pthread_cancel() function shall return zero;  other‐
35       wise, an error number shall be returned to indicate the error.
36

ERRORS

38       The  pthread_cancel()  function  shall  not  return  an  error  code of
39       [EINTR].
40
41       The following sections are informative.
42

EXAMPLES

44       None.
45

APPLICATION USAGE

47       None.
48

RATIONALE

50       Two alternative functions were considered for sending the  cancellation
51       notification to a thread. One would be to define a new SIGCANCEL signal
52       that had the cancellation semantics when delivered; the  other  was  to
53       define  the new pthread_cancel() function, which would trigger the can‐
54       cellation semantics.
55
56       The advantage of a new signal was that so much of the delivery criteria
57       were identical to that used when trying to deliver a signal that making
58       cancellation notification a signal was seen as consistent. Indeed, many
59       implementations  implement  cancellation using a special signal. On the
60       other hand, there would be no signal functions that could be used  with
61       this  signal  except  pthread_kill(), and the behavior of the delivered
62       cancellation signal would be unlike  any  previously  existing  defined
63       signal.
64
65       The  benefits  of  a special function include the recognition that this
66       signal would be defined because of the similar  delivery  criteria  and
67       that  this  is  the only common behavior between a cancellation request
68       and a signal. In addition, the cancellation delivery mechanism does not
69       have  to  be  implemented  as  a  signal. There are also strong, if not
70       stronger, parallels with language exception mechanisms than  with  sig‐
71       nals that are potentially obscured if the delivery mechanism is visibly
72       closer to signals.
73
74       In the end, it was considered that as there were so many exceptions  to
75       the  use  of the new signal with existing signals functions it would be
76       misleading. A special function has resolved this problem.   This  func‐
77       tion was carefully defined so that an implementation wishing to provide
78       the cancellation functions on top of signals could do so.  The  special
79       function  also  means that implementations are not obliged to implement
80       cancellation with signals.
81
82       If an implementation detects use of a thread ID after the  end  of  its
83       lifetime, it is recommended that the function should fail and report an
84       [ESRCH] error.
85

FUTURE DIRECTIONS

87       None.
88

SEE ALSO

90       pthread_exit(), pthread_cond_timedwait(), pthread_join(), pthread_set‐
91       cancelstate()
92
93       The Base Definitions volume of POSIX.1‐2008, <pthread.h>
94
96       Portions  of  this text are reprinted and reproduced in electronic form
97       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
98       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
99       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
100       cal  and  Electronics  Engineers,  Inc  and  The  Open Group.  (This is
101       POSIX.1-2008 with the 2013 Technical Corrigendum  1  applied.)  In  the
102       event of any discrepancy between this version and the original IEEE and
103       The Open Group Standard, the original IEEE and The Open Group  Standard
104       is  the  referee document. The original Standard can be obtained online
105       at http://www.unix.org/online.html .
106
107       Any typographical or formatting errors that appear  in  this  page  are
108       most likely to have been introduced during the conversion of the source
109       files to man page format. To report such errors,  see  https://www.ker
110       nel.org/doc/man-pages/reporting_bugs.html .
111
112
113
114IEEE/The Open Group                  2013                   PTHREAD_CANCEL(3P)
Impressum