PreviousNext

Cancel Rules Summary

The following summarizes a set of cancel-related rules that should always be adhered to when programming with cancels:

· Applications should not use cancels as a synchronization mechanism. Condition variables should be used instead.

· pthread_mutex_lock( ) is not a cancellation point. Resources needing to be held exclusively for a long time should be protected by condition variables rather than mutexes, as this will not inhibit cancelability.

· A condition wait (via pthread_cond_wait( ) or pthread_cond_timedwait( )) is a cancellation point. A side effect of acting on a cancellation request while in a condition wait is that the mutex is (in effect) reacquired. The effect is as if the thread were unblocked, allowed to execute up to the point of returning from the wait, but at that point notices the cancellation request and handles it instead of returning.

· In general, most library calls cannot be assumed to be asynchronous cancel safe, and hence must not be called with cancelability state set to asynchronous.

· Cleanup routines should never exit via longjmp( ) or siglongjmp( ).

In addition to the material covered in this topic, RPC Threads and RPC Cancel Semantics covers the additional semantics of cancels as applied to RPC threads.