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


pthread_attr_init

Initializes a thread attributes object.

Syntax

pthread_attr_init(
                  attr );
 


Argument Data Type Access

attr opaque pthread_attr_t write


C Binding

#include 

int pthread_attr_init ( pthread_attr_t *attr);

Arguments

attr
Thread attributes object to be initialized.

Description

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.

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 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:
Return        Description

0 Successful completion. [EINVAL] The value specified by attr is invalid. [ENOMEM] Insufficient memory exists to initialize the thread attributes object.


Associated Routines

   pthread_attr_destroy
   pthread_attr_setdetachstate
   pthread_attr_setguardsize_np
   pthread_attr_setinheritsched
   pthread_attr_setschedparam
   pthread_attr_setschedpolicy
   pthread_attr_setstacksize
   pthread_setguardsize_np
   pthread_create



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