#### 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).

· During the timeslice interruption.

· Within the DCE threads I/O wrappers for system calls that block. These are as follows:

- read( )

- readv( )

- select( )

- write( )

- writev( )

- accept( )

- connect( )

- recv( )

- recvmsg( )

- recvfrom( )

- send( )

- sendmsg( )

- sendto( )

· When pthread_setasynccancel( ) is called, and either of the following apply:

- It has set the cancelability state to asynchronous (general cancelability and asynchronous cancelability are both enabled), it hasn't yet returned, and a cancel is pending.

- It was called to disable asynchronous cancelability state, but hasn't yet done so, and a cancellation request has been asynchronously delivered.

One important blocking routine that is not a cancellation point is pthread_mutex_lock( ), as this would create a domino effect so that every routine calling it would also become a cancellation point. Thus, mutexes should be used only to protect resources held for a short period of time so that noncancelability will not be a problem. Resources needing to be held exclusively should be protected by condition variables rather than mutexes, as this will not inhibit cancelability.

If a thread has not set disabled cancelability state, a cancellation request has been made to that thread, and the thread executes pthread_testcancel( ), the cancellation request must be acted upon. Similarly, if a thread has not set disabled cancelability state, a cancellation request has been made to that thread, and the thread is blocked at a cancellation point waiting for an event to occur, then that thread must act upon the cancellation request. However, if a thread is suspended at a cancellation point and the event for which it is waiting has completed before a cancellation request is received and acted upon, the thread may resume normal execution and the cancellation request remains pending.

####