[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions, 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 (state, oldstate) 
int state;
int *oldstate;

int pthread_setcanceltype (type, oldtype)
int type;
int *oldtype;

int pthread_testcancel (void)

Description

The pthread_setcancelstate subroutine 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 subroutine 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 subroutine creates a cancellation point in the calling thread. The pthread_testcancel subroutine 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.
type Specifies the new cancelability type to set.
oldtype Points to where the previous cancelability type value will be stored.

Return Values

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

Error Codes

The pthread_setcancelstate subroutine will fail if:

EINVAL The specified state is not PTHREAD_CANCEL_ENABLE or PTHREAD_CANCEL_DISABLE.

The pthread_setcanceltype subroutine will fail if:

EINVAL The specified type is not PTHREAD_CANCEL_DEFERRED or PTHREAD_CANCEL_ASYNCHRONOUS.

These subroutines will not return an error code of EINTR.

Related Information

The pthread_cancel (pthread_cancel Subroutine) subroutine.

The pthread.h file.

Terminating Threads in AIX 5L Version 5.2 General Programming Concepts: Writing and Debugging Programs.

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

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]