Skip to content
Search

Pthread cancel

lastmod 2019-12-20created 2019-12-192 edits

Sends a cancellation request to the thread whose thread identifier is given as the argument thread.

pthread_setcancelstate

pthread_setcancelstate is used to change the cancelability state of the calling thread.

PTHREAD_CANCEL_ENABLE
Enables the cancelability state.
PTHREAD_CANCEL_DISABLE
Disables the cancelability state.

pthread_setcanceltype

pthread_setcanceltype is used to determine how a thread that receives a cancellation request reacts (the cancel type). The kind of reaction can be set through type.

Naturally, this function is meaningless if the cancelability state is PTHREAD_CANCEL_DISABLE.

PTHREAD_CANCEL_ASYNCHRONOUS
Terminates immediately.
PTHREAD_CANCEL_DEFERRED
In the latter case, it waits until it leaves a cancellation point.

Default argument

Without any particular settings, threads created with pthread_create are created in the PTHREAD_CANCEL_ENABLE, PTHREAD_CANCEL_DEFERRED state.

Cancellation points

Cancellation points are functions such as the following. A thread that has received a cancellation request waits at a cancellation point and terminates when it leaves it.

  • pthread_join(3)
  • pthread_cond_wait(3)
  • pthread_cond_timedwait(3)
  • pthread_testcancel(3)
  • sem_wait(3)
  • sigwait(3)

See also

Favorite site

author Zer0 sitemap