Enables or disables the current thread's asynchronous cancelability.
old_state = pthread_setasynccancel( state );
Argument Data Type Accessstate integer read
int pthread_setasynccancel ( int state);
Value DescriptionCANCEL_ON Asynchronous cancelability is enabled. CANCEL_OFF Asynchronous cancelability is disabled.
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 cancellation 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 cancellation state. Next, call this routine a second time specifying CANCEL_ON to enable asynchronous cancelability and ignore the result 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. See Example 2-1.
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.
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 Description0 Successful completion. -1 [EINVAL] The specified state is not CANCEL_ON or CANCEL_OFF.