Cancellation
Cancelling a Thread
int pthread_cancel(pthread_t);
- Registers a cancellation event with the specified thread.
- There is no way to unregister a cancellation event.
- Does not wait for the thread to terminate.
- Joining with a cancelled thread will return get a status of
PTHREAD_CANCELLED
Controlling Cancellation
- A thread must be in one of three cancellable states...
disabled, deferred, or asynchronous
- A thread always starts its life in the deferred state.
int pthread_setcancelstate(int state, int * old_state);
PTHREAD_CANCEL_ENABLE, PTHREAD_CANCEL_DISABLE
int pthread_setcanceltype(int type, int * old_type);
PTHREAD_CANCEL_ASYNCHRONOUS, PTHREAD_CANCEL_DEFERRED
Deferred Cancellation
- Deferred cancellation can only occur at certain point
- Usually a blocking syscall is a cancellation point
- Mutexes are NEVER a cancellation point
void pthread_testcancel(void);
- pthread_testcancel is a cancelation point
- It does nothing if cancellation is disabled
- There is no nondestructive test for a cancelation event.
Prepared by
Chris Provenzano (proven@mit.edu)