Multithreaded Programming Guide

Enable or Disable Cancellation

pthread_setcancelstate(3THR)

Use pthread_setcancelstate(3THR) to enable or disable thread cancellation. When a thread is created, thread cancellation is enabled by default.

Prototype:

int	pthread_setcancelstate(int state, int *oldstate);
#include <pthread.h>

int oldstate;
int ret;

/* enabled */
ret = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);

/* disabled */
ret = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);

Return Values

pthread_setcancelstate() returns zero after completing successfully. Any other returned value indicates that an error occurred. When the following condition occurs, the pthread_setcancelstate() function fails and returns the corresponding value.


EINVAL

The state is not PTHREAD_CANCEL_ENABLE or PTHREAD_CANCEL_DISABLE.