[ Previous | Next | Contents | Glossary | Home | Search ]
AIX Version 4.3 Base Operating System and Extensions Technical Reference, Volume 1

pthread_setcancelstate, pthread_setcanceltype or pthread_testcancel Subroutines

Purpose

Sets the calling thread's cancelability state.

Library

Threads Library (libpthreads.a)

Syntax

#include <pthread.h>
int pthread_setcancelstate (int state, int *oldstate);
int pthread_setcanceltype (int type, int *oldstype);
int pthread_testcancel (void);

Description

The pthread_setcancelstate function atomically both sets the calling thread's cancelability state to the indicated state and returns the previous cancelability state at the location referenced by oldstate. Legal values for state are PTHREAD_CANCEL_ENABLE and PTHREAD_CANCEL_DISABLE.

The pthread_setcanceltype function atomically both sets the calling thread's cancelability type to the indicated type and returns the previous cancelability type at the location referenced by oldtype. Legal values for type are PTHREAD_CANCEL_DEFERRED and PTHREAD_CANCEL_ASYNCHRONOUS.

The cancelability state and type of any newly created threads, including the thread in which main was first invoked, are PTHREAD_CANCEL_ENABLE and PTHREAD_CANCEL_DEFERRED respectively.

The pthread_testcancel function creates a cancellation point in the calling thread. The pthread_testcancel function has no effect if cancelability is disabled.

Parameters

state Specifies the new cancelability state to set. It must have one of the following values:
PTHREAD_CANCEL_DISABLE
Disables cancelability; the thread is not cancelable. Cancellation requests are held pending.
PTHREAD_CANCEL_ENABLE
Enables cancelability; the thread is cancelable, according to its cancelability type. This is the default value.
oldstate Points to where the previous cancelability state value will be stored.

Return Values

If successful, the pthread_setcancelstate and pthread_setcanceltype functions return zero. Otherwise, an error number is returned to indicate the error.

Error Codes

The pthread_setcancelstate function will fail if:

EINVAL The specified state is not PTHREAD_CANCEL_ENABLE or PTHREAD_CANCEL_DISABLE.

The pthread_setcanceltype function will fail if:

EINVAL The specified type is not PTHREAD_CANCEL_DEFERRED or PTHREAD_CANCEL_ASYNCHRONOUS.

These functions will not return an error code of EINTR.

Implementation Specifics

This subroutine is part of the Base Operating System (BOS) Runtime.

Related Information

The pthread_cancel subroutine, the pthread.h file.

Terminating Threads in AIX Version 4.3 General Programming Concepts: Writing and Debugging Programs.

Threads Library Quick Reference in AIX Version 4.3 General Programming Concepts: Writing and Debugging Programs.


[ Previous | Next | Contents | Glossary | Home | Search ]