OSF DCE Application Development Guide--Introduction and Style Guide

OSF DCE Application Development Guide—Introduction and Style Guide
2.3.3.1 Cancelability State
A thread’s cancelability state is determined by the combination of two substates: general
cancelability and asynchronous cancelability. These substates can be set to either
CANCEL_ON or CANCEL_OFF by calls to the routines pthread_setcancel( ) and
pthread_setasynccancel( ) respectively. A thread’s cancelability state is determined by
its general and asynchronous cancelability substates, as shown in Table 2-2.
TABLE 2-2. Cancelability State
_______________________________________________
General Asynchronous Cancelability
Cancelability Cancelability State
_______________________________________________
_______________________________________________
CANCEL_OFF CANCEL_OFF disabled
_______________________________________________
CANCEL_OFF CANCEL_ON disabled
_______________________________________________
CANCEL_ON CANCEL_OFF deferred
_______________________________________________
CANCEL_ON CANCEL_ON asynchronous
_______________________________________________
One awkwardness introduced by this mechanism for setting cancelability state is that
threads cannot easily determine their current cancelability state, although
pthread_setcancel() and pthread_setasynccancel( ) return the previous substates.
When a thread is created, the default cancelability state is deferred (general
cancelability set to CANCEL_ON, asynchronous cancelability set to CANCEL_OFF).
A thread that needs to discover its current cancelability state should explicitly maintain
this state in some place where it can be easily queried.
2.3.3.2 Cancellation Points
Applications need to be aware of where cancellation may actually occur when
cancelability state is set to deferred. Cancellation points are points inside certain
functions where a thread must act upon any pending cancellation request when
cancelability state is deferred if the function would block indefinitely. If cancelability
state is asynchronous, then every point is a cancellation point; that is, the thread may be
canceled at any time.
If cancelability state is deferred then cancellation may occur at the following points:
While waiting on a condition variable; that is, within pthread_cond_wait() or
pthread_cond_timedwait( ).
While awaiting the termination of another thread (within pthread_join( ).)
When pthread_testcancel( ) is called.
When sigwait( ) is called.
When a thread is waiting within pthread_delay_np( ) (not a portable routine).
2 10 Tandem Computers Incorporated 124246