pthread_setcancel(3thr)pthread_setcancel(3thr)Namepthread_setcancel - Enables or disables the current thread's general
cancelability.
Syntax
#include <pthread.h>
int pthread_setcancel (state)
int state;
Arguments
state State of general cancelability to set for the calling thread.
Valid values are as follows:
Value Description
CANCEL_ON Asynchronous cancelability
is enabled.
CANCEL_OFF Asynchronous cancelability
is disabled.
Description
This routine enables or disables the current thread's general cancela‐
bility and returns the previous cancelability state.
When general cancelability is set to CANCEL_OFF, a cancel cannot be
delivered to the thread, even if a cancelable routine is called or
asynchronous cancelability is enabled.
When a thread is created, the default general cancelability state is
CANCEL_ON.
Possible Dangers of Disabling Cancelability
The most important use of cancels is to ensure that indefinite wait
operations are terminated. For example, a thread waiting on some net‐
work connection, which may take days to respond (or may never respond),
is normally made cancelable.
However, when cancelability is disabled, no routine is cancelable.
Waits must be completed normally before a cancel can be delivered. As
a result, the program stops but does not crash and the user is unable
to cancel the operation.
When disabling cancelability, be sure that no long waits can occur or
that it is necessary for other reasons to defer cancels around that
particular region of code.
Return Values
On successful completion, this routine returns the previous state of
general cancelability.
If an error condition occurs, this routine returns -1 and sets errno to
the corresponding error value. Possible return values are as follows.
Return Error Description
0 Successful comple‐
tion.
-1 [EINVAL] The specified state
is not CANCEL_ON or
CANCEL_OFF.
pthread_setcancel(3thr)