Multithreaded Programming Guide

Cancelling a Thread

Use pthread_cancel(3C) to cancel a thread.

pthread_cancel Syntax

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(3C) and pthread_setcanceltype(3C) , determine that state.

pthread_cancel Return Values

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


ESRCH

Description:

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