To make a thread asynchronously cancelable, use pthread_setcanceltype.
The first argument should be
PTHREAD_CANCEL_ASYNCHRONOUS to make the thread asynchronously cancelable, or
PTHREAD_CANCEL_DEFERRED to return it to the synchronously cancelable state.
The second argument, if not null, is a pointer to a variable that will receive the previous cancellation type for the thread.
To create a cancellation point is to call pthread_testcancel. You should call pthread_testcancel periodically during lengthy computations in a thread function, at points where the thread can be canceled without leaking any resources or producing other ill effects.