Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ pthread_attr_setdetach_np(3) — Digital UNIX 3.2c

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

pthread_attr_create(3)

pthread_attr_getdetach_np(3)

pthread_create(3)

pthread_attr_setdetach_np(3)  —  Subroutines

NAME

pthread_attr_setdetach_np − Changes the detachstate attribute of thread creation. 

SYNOPSIS

#include <pthread.h>
int pthread_attr_setdetach_np(

pthread_attr_t ∗attr ,
int ∗detachstate );

PARAMETERS

attrThread attributes object to be modified. 

inheritNew value of the detachstate attribute. Valid values are as follows:

PTHREAD_CREATE_JOINABLE
This is the default value. Threads will be created in undetached state.

PTHREAD_CREATE_DETACHED
The created thread is detached immediately before it begins running.

DESCRIPTION

This routine changes the detachstate  attribute of thread creation. The attribute specifies whether threads created using the specified thread attributes object are created in detached state. 

You cannot use the thread handle (the value of type thread_t that is returned by pthread_create for a detached thread.  This means that you cannot cancel the thread with pthread_cancel.  You also cannot use pthread_join to wait for the thread to complete or to retrieve the thread’s return status. 

When a thread which has not been detached completes execution, DECthreads will retain the state of that thread to allow another thread to join with it.  If the thread is detached before it completes, DECthreads is free to immediately reclaim the thread’s storage and resources.  Failing to detach threads that have completed execution can result in wasting resources, so it’s a good idea to detach threads as soon as the program is done with them.  If there is no need to use the thread’s handle after creation it’s best to create the thread initially detached. 

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 value specified by detachstate is invalid. 
−1 [ESRCH] The value specified by attr does not refer to an existing thread attributes object. 

RELATED INFORMATION

pthread_attr_create(3), pthread_attr_getdetach_np(3), pthread_create(3)

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