The thread attributes structure
QNX SDP8.0Getting Started with the QNX OSDeveloperUser
When you start a new thread, it can assume some well-defined defaults, or you can explicitly specify its characteristics.
Before we jump into a discussion of the thread attribute functions, let's look at the
pthread_attr_t data type:
typedef struct {
int __flags;
size_t __stacksize;
void *__stackaddr;
void (*__exitfunc)(void *status);
int __policy;
struct sched_param __param;
unsigned __guardsize;
} pthread_attr_t;
Basically, the fields are used as follows:
- __flags
- Non-numerical (Boolean) characteristics (e.g., whether the thread should
run
detached
orjoinable
). - __stacksize, __stackaddr, and __guardsize
- Stack specifications.
- __exitfunc
- Function to execute at thread exit.
- __policy and __param
- Scheduling parameters.
The following functions are available:
- Attribute administration
- Flags (Boolean characteristics)
- Stack related
-
- pthread_attr_getguardsize()
- pthread_attr_setguardsize()
- pthread_attr_getstack()
- pthread_attr_setstack()
- pthread_attr_getstackaddr()
- pthread_attr_setstackaddr()
- pthread_attr_getstacklazy()
- pthread_attr_setstacklazy()
- pthread_attr_getstackprealloc()
- pthread_attr_setstackprealloc()
- pthread_attr_getstacksize()
- pthread_attr_setstacksize()
- Scheduling related
This looks like a pretty big list, but in reality we have to worry about only half
of them, because they're paired: get
and set
(with the
exception of pthread_attr_init() and pthread_attr_destroy()).
Before we examine the attribute functions, there's one thing to note. You must call pthread_attr_init() to initialize the attribute structure before using it, set it with the appropriate pthread_attr_set*() function(s), and then call pthread_create() to create the thread. Changing the attribute structure after the thread has been created has no effect.
Page updated: