Thread Cancellation

Thread cancellation allows a thread to be cancelled before it is finished. This is generally done in one of two ways:

Invoking a cancellation requests that a thread be cancelled. This request will remain pending if the thread is not in a state in which it can be cancelled, e.g. the thread may have disabled cancellations for a period, the request will remanin pending until it re-enables cancellation.

The usual choice is Deferred. In POSIX pthreads, cancellation will only occur at a cancellation point, i.e. when $pthread_testcancel()$ is called. When a thread is cancelled a cleanup handler is then invoked.