pthread_setcanceltype

Sets the cancellation type for the calling thread.

Library:LibC
Classification:POSIX
Service:Threads

Syntax

  #include <pthread.h>
   
  int   pthread_setcanceltype (
     int    type,
     int   *oldtype);
  

Parameters

type

(IN) Specifies the new cancellation type for the thread using one of the following flags:

Flag

Value

Description

PTHREAD_CANCEL_ASYNCHRONOUS

1

If cancellation is enabled, the cancellation request is carried out immediately.

PTHREAD_CANCEL_DEFERRED

2

If cancellation is enabled, the cancellation is deferred until the thread reaches a cancellation point.

oldtype

(OUT) Points to the previous value for the cancellation type.

Return Values

If successful, returns 0; otherwise returns a nonzero error code:

Decimal

Constant

Description

9

EINVAL

The specified type is invalid.

Remarks

By default when a thread is created, the cancellation type is set to PTHREAD_CANCEL_DEFERRED.

When the cancel state is PTHREAD_CANCEL_ENABLE and the cancellation type is set to PTHREAD_CANCEL_DEFERRED, the thread can only receive a cancel at specific cancellation points, which include condition waits, thread joins, and calls to pthread_testcancel.

If the cancel state is PTHREAD_CANCEL_ENABLE and its cancellation type is THREAD_CANCEL_ASYNCHRONOUS, the thread can be canceled at any point in its execution.

IMPORTANT:If the asynchronous cancellation type is set, do not call any routine unless it is explicitly documented as safe to be called with an asynchronous cancellation type.

See Also