pthread_attr_init(3T) DG/UX R4.11MU05 pthread_attr_init(3T)
NAME
pthread_attr_init, pthread_attr_destroy - thread attributes objects
SYNOPSIS
#include <pthread.h>
int pthread_attr_init(pthread_attr_t *attr);
int pthread_attr_destroy(pthread_attr_t *attr);
where:
attr A pointer to a thread attributes object
DESCRIPTION
Thread attributes objects are opaque collections of thread attributes
that are used to override the default creation attributes, such as
the stack size, in calls to pthread_create(). They can also be used
to change certain scheduling attributes, such as scheduling policy
and priority, of existing threads in calls to pthread_setschedattr().
Thread attributes objects are manipulated only by object-oriented
functions described here and in other man pages listed below. The
use of opaque attributes objects provides a clean isolation of the
configurable aspects of threads and an extensible mechanism for
adding vendor-specific attributes and future standard attributes.
Typically, an application initializes one or more attributes objects
in a well-isolated, possibly vendor-specific, place in its code.
Then those attributes objects are passed, in a standard way, to
pthread_create(). Hence most of the application code remains
portable, while a small portion may change to take advantage of the
underlying operating system. Moreover, different attributes objects
can be used to set up "classes" of threads with similar attributes.
For example, stack size is an important attribute of a thread, but it
cannot be expressed portably. When porting a threaded program, stack
sizes must often be adjusted. The use of attributes objects can help
by allowing the changes to be isolated in a single place, rather than
being spread across every instance of thread creation.
Standard attributes are provided to specify the size of the thread's
stack, whether or not the thread is created as detached, and how it
will will be scheduled. The scheduling attributes are the only
attributes that can be modified or retrieved for an existing thread.
DG/UX provides an additional attribute that can be used to create
threads in specific DG thread groups for purposes of maximizing the
affinity of computationally related threads. While this attribute is
DG-specific, its manipulation, like that of other attributes, can be
well-isolated in an application.
Before a thread attributes object can be used, it must be initialized
by a call to pthread_attr_init(). After it has been initialized,
individual attributes are specified by other object-oriented calls,
and then the attributes object is passed to a call to
pthread_create() or pthread_setschedattr(). Upon return from such a
call, the attributes object is no longer associated with the affected
thread, and can be destroyed by a call to pthread_attr_destroy(). If
desired, the attributes object can instead be used in subsequent
calls to pthread_create() or pthread_setschedattr().
The following functions initialize and destroy thread attributes
objects:
pthread_attr_init()
This function initializes the thread attributes object pointed to by
attr with the default values for all thread attributes. Consult the
other man pages below for the default values under DG/UX.
pthread_attr_destroy()
This function destroys the thread attributes object pointed to by
attr. The attributes object should have been initialized by a
previous call to pthread_attr_init(). The behavior of using the
attributes object after it has been destroyed is undefined. If DG/UX
detects that an attributes object is uninitialized or destroyed, it
will cause the using function to fail with EINVAL.
DIAGNOSTICS
Returns
If successful, these functions return 0. Otherwise they return -1
and set errno to indicate the error.
Errors
For each of the following conditions, pthread_attr_destroy() returns
-1 and sets errno to the corresponding value:
[EINVAL] An invalid attributes object has been specified. This
occurs when DG/UX has detected that the attributes object
pointed to by attr has not been initialized by a previous
call to pthread_attr_init() or has been corrupted.
SEE ALSO
pthread_attr_setstacksize(3T), pthread_attr_getstacksize(3T),
pthread_attr_setdetachstate(3T), pthread_attr_getdetachstate(3T),
pthread_attr_setinheritsched(3T), pthread_attr_getinheritsched(3T),
pthread_attr_setsched(3T), pthread_attr_getsched(3T),
pthread_attr_setprio(3T), pthread_attr_getprio(3T),
pthread_create(3T), pthread_setschedattr(3T),
pthread_getschedattr(3T), dg_pthread_group_create(3T),
dg_pthread_attr_setgroup(3T), dg_pthread_attr_getgroup(3T).
NOTES
Attributes objects are provided for threads, mutexes, condition
variables, and DG thread groups. While the attributes vary from
entity to entity, the style of the interfaces is consistent. For DG
thread groups, scheduling attributes similar to those for threads are
provided, but they affect the global scheduling of the target thread
group.
The effect of passing a NULL pointer to pthread_create() is the same
as passing a pointer to a newly initialized thread attributes object.
Both cases cause the default attributes to be used.
Licensed material--property of copyright holder(s)