Multithreaded Programming Guide

pthread_cancel(3T)

Use pthread_cancel(3T) to cancel a thread.

Prototype:

int	pthread_cancel(pthread_t thread);
#include <pthread.h>

pthread_t thread;
int ret;

ret = pthread_cancel(thread);

How the cancellation request is treated depends on the state of the target thread. Two functions, pthread_setcancelstate(3T) and pthread_setcanceltype(3T), determine that state.

Return Values

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


ESRCH

No thread could be found corresponding to that specified by the given thread ID.