The cancelability state

The target thread is required to be in an appropriate cancelability state. The state is Boolean-cancelability (on the target thread, A) is either enabled or disabled; here is the API to set this up:

int pthread_setcancelstate(int state, int *oldstate);

The two possible cancelability states, the value provided as the first parameter, for a thread are as follows:

  • PTHREAD_CANCEL_ENABLE (default on creation)
  • PTHREAD_CANCEL_DISABLE

Clearly, the previous cancelability state will be returned in the second parameter, oldstate.) The target thread can only be canceled if its cancelability state is enabled. A thread's cancelability state is enabled by default upon creation.

This is a powerful feature of the framework: if the ...

Get Hands-On System Programming with Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.