The global errno variable is not used by these routines. To indicate errors, the pthread routines return integer values indicating the type of error.
Routine names with the _np suffix denote that the routine is not portable, with respect to the POSIX.1c standard. That is, the routine might not be available in implementations of POSIX.1c other than DECthreads.
Declares handlers to be called when the process forks a child.This routine is for Digital UNIX systems only.
C Binding #include <pthread.h>pthread_atfork(
prepare ,
parent ,
child );
Argument Data Type Access prepare Handler read parent Handler read child Handler read
int
pthread_atfork (
void (*prepare)(void),
void (*parent)(void),
void (*child)(void) );
prepare
Address of a procedure that performs the fork preparation handling. This routine is called in the parent process before creating the child.parent
Address of a procedure that performs the fork parent handling. This routine is called in the parent process after creating the child and before returning to the caller of fork(2).child
Address of a procedure that performs the fork child handling. This routine is called in the child process before returning to the caller of fork(2).
This routine allows a main program or library to control resources during a fork(2) operation by declaring fork handlers that are called before and after the fork(2) execution. The prepare fork handler is called before the fork(2) execution. The parent handler is called after the fork(2) execution within the parent process, and the child handler is called after fork(2) in the new child process. If no handling is desired, you can set any of the arguments to a NULL.Return Values If an error occurs, this routine returns an integer indicating the type of error. Possible return values are as follows:
Note
It is not legal to call pthread_atfork() from within a handler routine. Doing so could cause a deadlock.
Mutex locks might be held by threads that no longer exist in a child process and any associated state might be inconsistent. The program can avoid this problem by calling pthread_atfork() to provide code that acquires and releases locks critical to the child process. For example, if your library uses the mutex my_mutex, you might provide pthread_atfork() handlers like:
void my_prepare(void) { pthread_mutex_lock(&my_mutex); } void my_parent(void) { pthread_mutex_unlock(&my_mutex); } void my_child(void) { pthread_mutex_unlock(&my_mutex); /* Reinitialize state that doesn't apply...like heap owned */ /* by other threads */ } { . . . pthread_atfork(my_prepare, my_parent, my_child); . . fork(); }
Return | Description |
---|---|
0 | Successful completion. |
[ENOMEM] | Insufficient table space exists to record the fork handler addresses. |
Destroys a thread attributes object.
C Binding #include <pthread.h>pthread_attr_destroy(
attr );
Argument Data Type Access attr opaque pthread_attr_t modify
int
pthread_attr_destroy (
pthread_attr_t *attr);
attr
Thread attributes object to be destroyed.
This routine destroys a thread attributes object. Call this routine when a thread attributes object will no longer be referenced.Return Values If an error condition occurs, this routine returns an integer value indicating the type of error. Possible return values are as follows:Threads that were created using this thread attributes object are not affected by the destruction of the thread attributes object.
The results of calling this routine are unpredictable if the value specified by the attr argument refers to a thread attributes object that does not exist.
Return | Description |
---|---|
0 | Successful completion. |
[EINVAL] | The value specified by attr is invalid. |
Obtains the detachstate attribute of the specified thread attributes object.
C Binding #include <pthread.h>pthread_attr_getdetachstate(
attr ,
detachstate );
Argument Data Type Access attr opaque pthread_attr_t read detachstate integer write
int
pthread_attr_getdetachstate (
const pthread_attr_t *attr,
int *detachstate);
attr
Thread attributes object whose detachstate attribute is obtained.detachstate
Receives the value of the detachstate attribute.
This routine obtains the detachstate attribute of a thread attributes object. This attribute specifies whether threads created using the specified thread attributes object are created in a detached state.On successful completion, this routine returns a zero and the detachstate attribute is set in detachstate. A value of PTHREAD_CREATE_JOINABLE indicates the thread is not detached, and a value of PTHREAD_CREATE_DETACHED indicates the thread is detached.
See the pthread_attr_setdetachstate() description for information about the detachstate attribute.
Return Values If an error condition occurs, this routine returns an integer value indicating the type of error. Possible return values are as follows:
Return | Description |
---|---|
0 | Successful completion. |
[EINVAL] | The value specified by attr does not refer to an existing thread attributes object. |
Obtains the guardsize attribute of the specified thread attributes object.
C Binding #include <pthread.h>pthread_attr_getguardsize_np(
attr ,
guardsize );
Argument Data Type Access attr opaque pthread_attr_t read guardsize size_t write
int
pthread_attr_getguardsize_np (
const pthread_attr_t *attr
size_t *guardsize);
attr
Thread attributes object whose guardsize attribute is obtained.guardsize
Receives the value for the guardsize attribute. The guardsize argument specifies the minimum size in bytes of the guard area for a thread.
This routine obtains the minimum size, in bytes, of the guard area for the stack of a thread that is created using the attributes object specified by the attr argument.Return Values If an error condition occurs, this routine returns an integer value indicating the type of error. Possible return values are as follows:A guard area helps to detect stack overflows by preventing memory access beyond the thread's stack. Large guard areas are necessary when threads might allocate large structures on the stack.
Return | Description |
---|---|
0 | Successful completion. |
[EINVAL] | The value specified by attr is invalid. |
Obtains the inherit scheduling attribute of the specified thread attributes object.
C Binding #include <pthread.h>pthread_attr_getinheritsched(
attr ,
inheritsched );
Argument Data Type Access attr opaque pthread_attr_t read inheritsched integer write
int
pthread_attr_getinheritsched (
const pthread_attr_t *attr
int *inheritsched);
attr
Thread attributes object whose inherit scheduling attribute is obtained.inheritsched
Receives the value of the inherit scheduling attribute. Refer to the description of the pthread_attr_setinheritsched() function for valid values.
This routine obtains the value of the inherit scheduling attribute from the specified thread attributes object. The inherit scheduling attribute specifies whether threads created using the attributes object inherit the scheduling attributes of the creating thread, or use the scheduling attributes stored in the attributes object that is passed to pthread_create().Return Values If an error condition occurs, this routine returns an integer value indicating the type of error. Possible return values are as follows:
Return | Description |
---|---|
0 | Successful completion. |
[EINVAL] | The value specified by attr is invalid. |
Obtains the scheduling parameters for an attribute of the specified thread attributes object.
C Binding #include <pthread.h>pthread_attr_getschedparam(
attr ,
param );
Argument Data Type Access attr opaque pthread_attr_t read param struct sched_param write
int
pthread_attr_getschedparam (
const pthread_attr_t *attr,
struct sched_param *param);
attr
Thread attributes object of the scheduling policy attribute whose parameters are obtained.param
Receives the values of scheduling parameters for the scheduling policy attribute of the attributes object specified by the attr argument. Refer to the description of the pthread_attr_setschedparam() function for valid parameters and their values.
This routine obtains the scheduling parameters associated with the scheduling policy attribute of the specified thread attributes object.Return Values If an error condition occurs, this routine returns an integer value indicating the type of error. Possible return values are as follows:
Return | Description |
---|---|
0 | Successful completion. |
[EINVAL] | The value specified by attr is invalid. |
Obtains the scheduling policy attribute of the specified thread attributes object.
C Binding #include <pthread.h>pthread_attr_getschedpolicy(
attr ,
policy );
Argument Data Type Access attr opaque pthread_attr_t read policy integer write
int
pthread_attr_getschedpolicy (
const pthread_attr_t *attr,
int *policy);
attr
Thread attributes object whose scheduling policy attribute is obtained.policy
Receives the value of the scheduling policy attribute. Refer to the description of the pthread_attr_setschedpolicy() function for valid values.
This routine obtains the value of the scheduling policy attribute of the specified thread attributes object. The scheduling policy attribute defines the scheduling policy for threads created using the attributes object.Return Values If an error condition occurs, this routine returns an integer value indicating the type of error. Possible return values are as follows:
Return | Description |
---|---|
0 | Successful completion. |
[EINVAL] | The value specified by attr is invalid. |
Obtains the stacksize attribute of the specified thread attributes object.
C Binding #include <pthread.h>pthread_attr_getstacksize(
attr ,
stacksize );
Argument Data Type Access attr opaque pthread_attr_t read stacksize size_t write
int
pthread_attr_getstacksize (
const pthread_attr_t *attr,
size_t *stacksize);
attr
Thread attributes object whose stacksize attribute is obtained.stacksize
Receives the value for the stacksize attribute.
This routine obtains the stacksize attribute of the thread attributes object specified in attr.Return Values On successful completion, this routine returns a zero (0) and the stacksize value in the stacksize variable.
If an error condition occurs, this routine returns an integer value indicating the type of error. Possible return values are as follows:
Return | Description |
---|---|
0 | Successful completion. |
EINVAL | The value specified by attr is invalid. |
Initializes a thread attributes object.
C Binding #include <pthread.h>pthread_attr_init(
attr );
Argument Data Type Access attr opaque pthread_attr_t write
int
pthread_attr_init (
pthread_attr_t *attr);
attr
Thread attributes object to be initialized.
This routine initializes a thread attributes object that is used to specify the attributes of threads when they are created. The attributes object created by this routine is used only in calls to pthread_create().Return Values If an error condition occurs, the thread attributes object cannot be used and this routine returns an integer value indicating the type of error. Possible return values are as follows:The following routines change the initialized individual attributes of a thread attributes object:
- pthread_attr_setdetachstate()
- pthread_attr_setguardsize_np()
- pthread_attr_setinheritsched()
- pthread_attr_setschedparam()
- pthread_attr_setschedpolicy()
- pthread_attr_setstacksize()
The individual attributes (internal fields) of the attributes object are initialized to default values. The default values of each attribute are discussed in the descriptions of the thread attribute setting routines listed above.
When an attributes object is used to create a thread, the values of the individual attributes determine the characteristics of the new thread. Attributes objects act as additional arguments to thread creation. Changing individual attributes does not affect any threads that were previously created using the attributes object.
You can use a single attributes object in multiple calls to pthread_create(), from any thread. If multiple threads might change attributes in a shared attributes object, the application code must protect the integrity of the attributes object by using a mutex.
When you set the scheduling policy or scheduling parameters, or both, in an attributes object, you must disable scheduling inheritance if you want the scheduling attributes you set to be used at thread creation. To disable scheduling inheritance use the pthread_attr_setinheritsched() routine, specifying the value PTHREAD_EXPLICIT_SCHED for the inherit argument, before calling pthread_create().
Return | Description |
---|---|
0 | Successful completion. |
[EINVAL] | The value specified by attr is invalid. |
[ENOMEM] | Insufficient memory exists to initialize the thread attributes object. |
Changes the detachstate attribute in the specified thread attributes object.
C Binding #include <pthread.h>pthread_attr_setdetachstate(
attr ,
detachstate );
Argument Data Type Access attr opaque pthread_attr_t write detachstate integer read
int
pthread_attr_setdetachstate (
pthread_attr_t *attr,
int detachstate);
attr
Thread attributes object to be modified.detachstate
New value for the detachstate attribute. Valid values are as follows:
PTHREAD_CREATE_JOINABLE This is the default value. Threads are created in "undetached" state. PTHREAD_CREATE_DETACHED The created thread is detached immediately, before it begins running.
This routine changes the detachstate attribute in the thread creation attributes. This attribute specifies whether the threads created using the specified thread attributes object are created in a detached state or not. A value of PTHREAD_CREATE_JOINABLE indicates the thread is not detached, and a value of THREAD_CREATE_DETACHED indicates the thread is detached. PTHREAD_CREATE_JOINABLE is the default value.Return Values If an error condition occurs, this routine returns an integer value indicating the type of error. Possible return values are as follows:You cannot use the thread handle (the value of type pthread_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 | Description |
---|---|
0 | Successful completion. |
[EINVAL] | The value specified by the detachstate argument is invalid. |
Changes the guardsize attribute of the specified thread attributes object.
C Binding #include <pthread.h>pthread_attr_setguardsize_np(
attr ,
guardsize );
Argument Data Type Access attr opaque pthread_attr_t write guardsize size_t read
int
pthread_attr_setguardsize_np (
pthread_attr_t *attr,
size_t guardsize);
attr
Threads attributes object to be modified.guardsize
New value for the guardsize attribute. The guardsize argument specifies the minimum size (in bytes) of the guard area for the stack of a thread.
This routine sets the minimum size (in bytes) of the guard area for the stack of a thread that is created using the attributes object specified by the attr argument.Return Values If an error condition occurs, this routine returns an integer value indicating the type of error. Possible return values are as follows:A guard area helps to detect stack overflows by preventing memory access beyond the thread's stack. Large guard areas are necessary when threads might allocate large structures on the stack.
The default value is platform dependent, but will always be at least one "hardware protection unit" (at least one page).
Return | Description |
---|---|
0 | Successful completion. |
[EINVAL] | The value specified by attr is invalid. |
Changes the inherit scheduling attribute of the specified thread attributes object.
C Binding #include <pthread.h>pthread_attr_setinheritsched(
attr ,
inheritsched );
Argument Data Type Access attr opaque pthread_attr_t write inheritsched integer read
6493P007.HTM OSSG Documentation 22-NOV-1996 13:20:05.80
Copyright © Digital Equipment Corporation 1996. All Rights Reserved.