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(3T) call.
Threads waiting for the occurrence of a particular condition in pthread_cond_wait(3T) or pthread_cond_timedwait(3T).
Threads waiting for termination of another thread in pthread_join(3T).
Threads blocked on sigwait(2).
Some standard library calls. In general, these are functions in which threads can block; see the man page cancellation(3T) 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(3T)"for information about disabling cancellation.