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


pthread_setcancelstate

Sets the current thread's cancelability state.

Syntax

pthread_setcancelstate(
                       state,
                       oldstate );
 


Argument Data Type Access

state integer read oldstate integer write


C Binding

#include 

int pthread_setcancelstate ( int state, int *oldstate );

Arguments

state
State of general cancelability to set for the calling thread. The following are valid cancel state values:
oldstate
Previous cancelability state.

Description

This routine sets the current thread's cancelability state and returns the previous cancelability state in oldstate.

When cancelability state is set to PTHREAD_CANCEL_DISABLE, a cancel cannot be delivered to the thread, even if a cancelable routine is called or asynchronous cancelability type is enabled.

When a thread is created, the default general cancelability state is PTHREAD_CANCEL_ENABLE.

Possible Problems When Disabling Cancelability

The most important use of cancel calls 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.

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 in oldstate.

If an error condition occurs, this routine returns an integer value indicating the type of error. Possible return values are as follows:


Return        Description
0             Successful completion.

[EINVAL]      The specified state is not PTHREAD_CANCEL_ENABLE or
              PTHREAD_CANCEL_DISABLE.



Associated Routines

   pthread_cancel
   pthread_setcanceltype
   pthread_testcancel



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