1PTHREAD_CANCEL(P)          POSIX Programmer's Manual         PTHREAD_CANCEL(P)
2
3
4

NAME

6       pthread_cancel - cancel execution of a thread
7

SYNOPSIS

9       #include <pthread.h>
10
11       int pthread_cancel(pthread_t thread);
12
13

DESCRIPTION

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

RETURN VALUE

28       If  successful, the pthread_cancel() function shall return zero; other‐
29       wise, an error number shall be returned to indicate the error.
30

ERRORS

32       The pthread_cancel() function may fail if:
33
34       ESRCH  No thread could be found corresponding to that specified by  the
35              given thread ID.
36
37
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

FUTURE DIRECTIONS

83       None.
84

SEE ALSO

86       pthread_exit()   ,   pthread_cond_timedwait()   ,   pthread_join()    ,
87       pthread_setcancelstate()    ,    the   Base   Definitions   volume   of
88       IEEE Std 1003.1-2001, <pthread.h>
89
91       Portions of this text are reprinted and reproduced in  electronic  form
92       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
93       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
94       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
95       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
96       event of any discrepancy between this version and the original IEEE and
97       The Open Group Standard, the original IEEE and The Open Group  Standard
98       is  the  referee document. The original Standard can be obtained online
99       at http://www.opengroup.org/unix/online.html .
100
101
102
103IEEE/The Open Group                  2003                    PTHREAD_CANCEL(P)
Impressum