[Return to Bookshelf] [Contents] [Previous Section] [Next Section] [Index] [Help]


pthread_attr_setdetach_np

Changes the detachstate attribute of thread creation.

Syntax

pthread_attr_setdetach_np(pthread_attr_t *attr, int detachstate);
 


Argument Data Type Access

attr opaque pthread_attr_t read detachstate integer read


C Binding

int
pthread_attr_setdetach_np (
pthread_attr_t *attr,
int detachstate);

Arguments

attr
Thread attributes object to be modified.
detachstate
New value for the detachstate attribute. Valid values are as follows:
PTHREAD_CREATE_       This is the default value. Threads are created
JOINABLE              in "undetached" state.

PTHREAD_CREATE_       The created thread is detached immediately,
DETACHED              before it begins running.


Description

This routine changes the detachstate attribute of thread creation. This 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 that 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 threads should be detached as soon as the program is done with them. If there is no need to use the thread's handle after creation, 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 the detachstate attribute is invalid. -1 [ESRCH] The value specified by attr does not refer to an existing thread attributes object.



[Return to Bookshelf] [Contents] [Previous Section] [Next Section] [Index] [Help]