pthread_setasynccancel(3) — Subroutines
NAME
pthread_setasynccancel − Enables or disables the current thread’s asynchronous cancelability.
SYNOPSIS
#include <pthread.h>
int pthread_setasynccancel(
int state );
PARAMETERS
stateState of asynchronous cancelability set for the calling thread. Valid values are as follows:
CANCEL_ONAsynchronous cancelability is enabled.
CANCEL_OFF
Asynchronous cancelability is disabled.
DESCRIPTION
This routine enables or disables the current thread’s asynchronous cancelability and returns the previous cancelability state to the state parameter.
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 general cancelability is set to CANCEL_ON, cancelability depends on the state of the thread’s asynchronous cancelability.
When general cancelability is set to CANCEL_ON and asynchronous cancelability is set to CANCEL_OFF, the thread can only receive a cancel at specific cancelation points (for example, condition waits, thread joins and calls to pthread_testcancel). If both general cancelability and asynchronous cancelability are set to CANCEL_ON, the thread can be canceled at any point in its execution.
When a thread is created, the default asynchronous cancelability state is CANCEL_OFF.
If you call this routine to enable asynchronous cancelability, first call it specifying CANCEL_OFF to reliably obtain the previous cancelation state. Next, call this routine a second time specifying CANCEL_ON to enable asynchronous cancelability and ignore the result of of this second call. The result of the second call is not reliable because an asynchronous cancel may occur before the routine returns. The previous state of asynchronous delivery can be restored later by another call to this routine specifying the value returned by the call that specified CANCEL_OFF.
If asynchronous cancelability is enabled, do not call any routine unless it is explicitly documented as safe to be called with asynchronous cancelability enabled. Note that none of the general run-time libraries and none of the DECthreads libraries are safe except for pthread_setasynccancel and cma_alert_restore.
RETURN VALUES
On successful completion, this routine returns the previous state of asynchronous 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 completion. | |
| −1 | [EINVAL] | The specified state is not CANCEL_ON or CANCEL_OFF. |
RELATED INFORMATION
pthread_cancel(3), pthread_setcancel(3), pthread_testcancel(3)