The thread attributes structure

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:

Non-numerical (Boolean) characteristics (e.g., whether the thread should run "detached" or "joinable").
__stacksize, __stackaddr, and __guardsize
Stack specifications.
Function to execute at thread exit.
__policy and __param
Scheduling parameters.

The following functions are available:

Attribute administration
Flags (Boolean characteristics)
Stack related
Scheduling related

This looks like a pretty big list (20 functions), 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's been created has no effect.