Be careful to cancel a thread only when cancellation is safe. The pthreads standard specifies several cancellation points, including:
Programmatically establish a thread cancellation point through a pthread_testcancel(3THR) call.
Threads waiting for the occurrence of a particular condition in pthread_cond_wait(3THR) or pthread_cond_timedwait(3THR).
Threads waiting for termination of another thread in pthread_join(3THR).
Threads blocked on sigwait(2).
Some standard library calls. In general, these are functions in which threads can block; see the man page cancellation(3THR) for a list.
Cancellation is enabled by default. At times you might want an application to disable cancellation. This has the result of deferring all cancellation requests until they are enabled again.
See pthread_setcancelstate(3THR)for information about disabling cancellation.