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

NAME

12       pthread_cancel - cancel execution of a thread
13

SYNOPSIS

15       #include <pthread.h>
16
17       int pthread_cancel(pthread_t thread);
18
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 may fail if:
39
40       ESRCH  No  thread could be found corresponding to that specified by the
41              given thread ID.
42
43
44       The pthread_cancel()  function  shall  not  return  an  error  code  of
45       [EINTR].
46
47       The following sections are informative.
48

EXAMPLES

50       None.
51

APPLICATION USAGE

53       None.
54

RATIONALE

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

FUTURE DIRECTIONS

89       None.
90

SEE ALSO

92       pthread_exit(),  pthread_cond_timedwait(), pthread_join(), pthread_set‐
93       cancelstate(), the Base  Definitions  volume  of  IEEE Std 1003.1-2001,
94       <pthread.h>
95
97       Portions  of  this text are reprinted and reproduced in electronic form
98       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
99       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
100       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
101       Electrical  and  Electronics  Engineers, Inc and The Open Group. 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.opengroup.org/unix/online.html .
106
107
108
109IEEE/The Open Group                  2003                   PTHREAD_CANCEL(3P)
Impressum