pthread_setcancelstate

Sets the cancel state of the calling thread, which determines whether the thread can be cancelled.

Library:LibC
Classification:POSIX
Service:Threads

Syntax

  #include <pthread.h>
   
  int pthread_setcancelstate (
     int    state,
     int   *oldstate);
  

Parameters

state

(IN) Specifies the new cancel state for the thread using one of the following flags:

Flag

Value

Description

PTHREAD_CANCEL_DISABLE

0

Prevents the thread from being canceled.

PTHREAD_CANCEL_ENABLE

1

Allows the thread to be canceled.

oldstate

(OUT) Points to the old cancel state for the thread.

Return Values

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

Decimal

Constant

Description

9

EINVAL

The specified state is invalid.

Remarks

The cancel state of new threads is, by default, PTHREAD_CANCEL_ENABLE. When cancellation is enabled, the library performs cancellation at many points in its functions.

The pthread_setcancelstate function permits explicit cancellation-point management. A cancellation point is any point at which a thread might be suspended or killed. Many of the library's functions offer cancellation points upon entry and exit to or from the function. If a thread is holding a lock or other resource on which other threads might depend or wait, it must not be allowed to be cancelled by the library.

On NetWare, an application can call outside LibC into another library or service and acquire resources (especially locks) that are unknown to the library. It is probably best not to permit the library to kill or suspend the thread while it holds these resources.

See Also