[Return to Bookshelf] [Contents] [Previous Section] [Next Section] [Index] [Help]


pthread_setcancel

Enables or disables the current thread's general cancelability.

Syntax

int pthread_setcancel(
                      state );
 


Argument Data Type Access

state integer read


C Binding

int
pthread_setcancel (
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 cancelability 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 network connection, which may take days to respond (or may never respond), should be made cancelable.

However, when cancelability is disabled, no routine is cancelable. As a result, 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

CANCEL_ON Successful completion. CANCEL_ Successful completion. OFF -1 [EINVAL] The specified state is not CANCEL_ON or CANCEL_OFF.



[Return to Bookshelf] [Contents] [Previous Section] [Next Section] [Index] [Help]