pthread_attr_init, pthread_attr_destroy,
pthread_attr_setstacksize, pthread_attr_getstacksize,
pthread_attr_setstackaddr, pthread_attr_getstackaddr,
pthread_attr_setschedparam, pthread_attr_getschedparam,
pthread_attr_setdetachstate, pthread_attr_getdetachstate,
-
thread creation attributes
#include <pthread.h>
All pthread_attr_get* and pthread_attr_set* functions are callable from an ISR.
The pthread approach to setting attributes for threads is to request the initialization of an attribute object, attr , and pass the initialized attribute object to pthread_create().
All attributes in attr are independent of one another and may be singularly modified or retrieved. attr , itself, is independent of any thread and can be modified or used to create new threads. However, any change to attr after a thread is created will not affect that thread.
The pthread_attr_init() function initializes a thread attributes object ( attr ) with the default value for each attribute as follows:
|
Attribute |
Default |
|
stackaddr |
stack allocated by system |
|
stacksize |
processor specific |
|
priority |
priority of calling thread |
|
detachstate |
detach state of the thread |
|
policy |
currently ignored |
NOTE: Attribute objects should be destroyed before an initialized attribute object is re-initialized.
pthread_attr_destroy() destroys a thread attributes object ( attr ), which cannot be reused until it is reinitialized.
The pthread_attr_setstacksize() and pthread_attr_getstacksize() functions set and get the stacksize thread attribute in the attr object. The stacksize default argument is NULL, and a processor specific thread default stack size is used.
The pthread_attr_setstackaddr() and pthread_attr_getstackaddr() functions set and get the stackaddr thread attribute in the attr object. The stackaddr default is NULL (See pthread_create() ).
The pthread_attr_setschedparam() and pthread_attr_getschedparam() functions set and get the scheduling parameter thread attributes in the attr argument, determined by the scheduling policy set in the attr object. The only required member of the param structure for the SCHED_OTHER , SCHED_FIFO , and SCHED_RR policies is sched_priority (see NOTES section below). You can use these functions to get and set the priority of the thread to be created. The sched_priority of the param structure is NULL, by default, which means the newly created thread inherits the priority of its parent thread.
The pthread_attr_setdetachstate() and pthread_attr_getdetachstate() are used to find detach state information about current memory that is attached to the thread. The detachstate attribute controls whether the thread is created in a detached state. If the thread is created detached, then use of the ID of the newly created thread by the pthread_detach() or pthread_join() function is an error.
The pthread_attr_getdetachstate() and pthread_attr_setdetachstate() functions, respectively, shall get and set the detachstate attribute in the attr object.
For pthread_attr_getdetachstate(), detachstate shall be set to either PTHREAD_CREATE_DETACHED or PTHREAD_CREATE_JOINABLE.
For pthread_attr_setdetachstate(), the application shall set detachstate to either PTHREAD_CREATE_DETACHED or PTHREAD_CREATE_JOINABLE.
A value of PTHREAD_CREATE_DETACHED shall cause all threads created with attr to be in the detached state, whereas using a value of PTHREAD_CREATE_JOINABLE shall cause all threads created with attr to be in the joinable state. The default value of the detachstate attribute shall be PTHREAD_CREATE_JOINABLE.
Upon successful completion, the following functions return 0; otherwise, an error number is returned to indicate the error.
If any of the following conditions occur, pthread_attr_init() returns the corresponding error number:
If any of the following conditions occur, pthread_attr_setstacksize() returns the corresponding error number:
If any of the following conditions occur, pthread_attr_destroy() , pthread_attr_setstacksize() , pthread_attr_getstacksize() , pthread_attr_setstackaddr() , pthread_attr_getstackaddr() , pthread_attr_setschedparam() , and pthread_attr_getschedparam() return the corresponding error number:
If any of the following conditions occur, pthread_attr_setstacksize() returns the corresponding error number:
If any of the following conditions occur, pthread_attr_setschedparam() returns the corresponding error number:
If any of the following conditions occur, pthread_attr_getstacksize() returns the corresponding error number:
If any of the following conditions occur, pthread_attr_getstackaddr() returns the corresponding error number:
If any of the following conditions occur, either pthread_attr_setschedparam() and pthread_attr_getschedparam() returns the corresponding error number:
If any of the following conditions occur, either pthread_attr_setdetachstate() and pthread_attr_getdetachstate() returns the corresponding error number: