Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

pthread_cancel(3)

pthread_setasynccancel(3)

pthread_testcancel(3)

pthread_setcancel(3)  —  Subroutines

Digital

NAME

pthread_setcancel − Enables or disables the current thread’s general cancelability. 

SYNOPSIS

#include <pthread.h>
int pthread_setcancel(

int state );

PARAMETERS

stateState of general cancelability set for the calling thread. On return, receives the prior state of general cancelability. Valid values are as follows:

CANCEL_ONGeneral cancelability is enabled. 

CANCEL_OFF
General cancelability is disabled.

DESCRIPTION

This routine enables or disables the current thread’s general cancelability and returns the previous cancelability state to the state parameter. 

When general cancelability is set to CANCEL_OFF, a cancel cannot be delivered to the thread, even if a cancelable routine is called or asynchronous cancelability is enabled. 

When a thread is created, the default general cancelability state is CANCEL_ON. 

Possible Dangers of Disabling Cancelability

The most important use of cancels is to ensure that indefinite wait operations are terminated. For example, a thread waiting on some network connection, which may take days to respond (or may never respond), is normally made cancelable. 

However, when cancelability is disabled, no routine is cancelable. Waits must be completed normally before a cancel can be delivered. As a result, the program stops working and the user is unable to cancel the operation. 

When disabling cancelability, be sure that no long waits can occur or that it is necessary for other reasons to defer cancels around that particular region of code. 

RETURN VALUES

If an error condition occurs, this routine returns −1 and sets errno to the corresponding error value. Possible return values are as follows:

Return Error Description
 0 Successful completion.
−1 [EINVAL] The specified state is not CANCEL_ON or CANCEL_OFF. 

RELATED INFORMATION

pthread_cancel(3), pthread_setasynccancel(3), pthread_testcancel(3)

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026