pthread_threading_attr.h File Reference

Thread creation features (attributes). More...

Detailed Description

Note
Do not include this header file directly, but pthread.h.

Definition in file pthread_threading_attr.h.

+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  pthread_attr_t
 An attribute set to supply to pthread_create() More...
 
struct  sched_param
 This structure is unused right now, and only exists for POSIX compatibility. More...
 
#define PTHREAD_CREATE_JOINABLE   (0)
 Create new pthread as joinable (default). More...
 
#define PTHREAD_CREATE_DETACHED   (1)
 Create new pthread in detached state. More...
 
int pthread_attr_init (pthread_attr_t *attr)
 Initialize attributes for a new pthread. More...
 
int pthread_attr_destroy (pthread_attr_t *attr)
 Destroys an attribute set. More...
 
int pthread_attr_getdetachstate (const pthread_attr_t *attr, int *detachstate)
 Tells whether to create a new pthread in a detached state. More...
 
int pthread_attr_setdetachstate (pthread_attr_t *attr, int detachstate)
 Sets whether to create a new pthread in a detached state. More...
 
int pthread_attr_getguardsize (const pthread_attr_t *attr, size_t *guardsize)
 This function is unused right now, and only exists for POSIX compatibility. More...
 
int pthread_attr_setguardsize (pthread_attr_t *attr, size_t guardsize)
 This function is unused right now, and only exists for POSIX compatibility. More...
 
int pthread_attr_getschedparam (const pthread_attr_t *attr, struct sched_param *param)
 This function is unused right now, and only exists for POSIX compatibility. More...
 
int pthread_attr_setschedparam (pthread_attr_t *attr, const struct sched_param *param)
 This function is unused right now, and only exists for POSIX compatibility. More...
 
int pthread_attr_getschedpolicy (const pthread_attr_t *attr, int *policy)
 This function is unused right now, and only exists for POSIX compatibility. More...
 
int pthread_attr_setschedpolicy (pthread_attr_t *attr, int policy)
 This function is unused right now, and only exists for POSIX compatibility. More...
 
int pthread_attr_getinheritsched (const pthread_attr_t *attr, int *inherit)
 This function is unused right now, and only exists for POSIX compatibility. More...
 
int pthread_attr_setinheritsched (pthread_attr_t *attr, int inherit)
 This function is unused right now, and only exists for POSIX compatibility. More...
 
int pthread_attr_getscope (const pthread_attr_t *attr, int *scope)
 This function is unused right now, and only exists for POSIX compatibility. More...
 
int pthread_attr_setscope (pthread_attr_t *attr, int scope)
 This function is unused right now, and only exists for POSIX compatibility. More...
 
int pthread_attr_getstackaddr (const pthread_attr_t *attr, void **stackaddr)
 Query assigned stack for new pthread. More...
 
int pthread_attr_setstackaddr (pthread_attr_t *attr, void *stackaddr)
 Set address of the stack to use for the new pthread. More...
 
int pthread_attr_getstacksize (const pthread_attr_t *attr, size_t *stacksize)
 Query set stacksize for new pthread. More...
 
int pthread_attr_setstacksize (pthread_attr_t *attr, size_t stacksize)
 Set the stack size for the new pthread. More...
 

Macro Definition Documentation

#define PTHREAD_CREATE_DETACHED   (1)

Definition at line 45 of file pthread_threading_attr.h.

#define PTHREAD_CREATE_JOINABLE   (0)

Definition at line 44 of file pthread_threading_attr.h.

Function Documentation

int pthread_attr_destroy ( pthread_attr_t attr)

Since pthread_attr_t does not hold dynamic data, this is a no-op.

Returns
0, since this a no-op that cannot fail
int pthread_attr_getdetachstate ( const pthread_attr_t attr,
int *  detachstate 
)
Parameters
[in]attrAttribute set to query.
[out]detachstateEither PTHREAD_CREATE_JOINABLE or PTHREAD_CREATE_DETACHED.
Returns
0, the invocation cannot fail
int pthread_attr_getguardsize ( const pthread_attr_t attr,
size_t *  guardsize 
)
Parameters
[in]attrUnused
[out]guardsizeUnused
Returns
-1, this function fails
int pthread_attr_getinheritsched ( const pthread_attr_t attr,
int *  inherit 
)
Parameters
[in]attrUnused
[out]inheritUnused
Returns
-1, this function fails
int pthread_attr_getschedparam ( const pthread_attr_t attr,
struct sched_param param 
)
Parameters
[in]attrUnused
[out]paramUnused
Returns
-1, this function fails
int pthread_attr_getschedpolicy ( const pthread_attr_t attr,
int *  policy 
)
Parameters
[in]attrUnused
[out]policyUnused
Returns
-1, this function fails
int pthread_attr_getscope ( const pthread_attr_t attr,
int *  scope 
)
Parameters
[in]attrUnused
[out]scopeUnused
Returns
-1, this function fails
int pthread_attr_getstackaddr ( const pthread_attr_t attr,
void **  stackaddr 
)
See also
pthread_attr_setstackaddr() for more information
Parameters
[in]attrAttribute set to query
[out]stackaddrPointer to previously assigned stack, or NULL for dynamic allocation.
Returns
0, this invocation cannot fail
int pthread_attr_getstacksize ( const pthread_attr_t attr,
size_t *  stacksize 
)

Returns default stack size of the value is yet unset.

Parameters
[in]attrAttribute set to query.
[out]stacksizeAssigned or default stack size, resp.
Returns
0, this invocation cannot fail
int pthread_attr_init ( pthread_attr_t attr)
See also
pthread_create()

A zeroed out attr is initialized.

Parameters
[in,out]attrStructure to initialize
Returns
0, invocation cannot fail
int pthread_attr_setdetachstate ( pthread_attr_t attr,
int  detachstate 
)
Note
Supplying a value different form PTHREAD_CREATE_JOINABLE or PTHREAD_CREATE_DETACHED causes undefined behavior.
Parameters
[in,out]attrAttribute set to operate on.
[in]detachstateEither PTHREAD_CREATE_JOINABLE or PTHREAD_CREATE_DETACHED.
Returns
0 on success. -1 if you managed to supply an illegal value in detachstate.
int pthread_attr_setguardsize ( pthread_attr_t attr,
size_t  guardsize 
)
Parameters
[in,out]attrUnused
[in]guardsizeUnused
Returns
-1, this function fails
int pthread_attr_setinheritsched ( pthread_attr_t attr,
int  inherit 
)
Parameters
[in,out]attrUnused
[in]inheritUnused
Returns
-1, this function fails
int pthread_attr_setschedparam ( pthread_attr_t attr,
const struct sched_param param 
)
Parameters
[in,out]attrUnused
[in]paramUnused
Returns
-1, this function fails
int pthread_attr_setschedpolicy ( pthread_attr_t attr,
int  policy 
)
Parameters
[in,out]attrUnused
[in]policyUnused
Returns
-1, this function fails
int pthread_attr_setscope ( pthread_attr_t attr,
int  scope 
)
Parameters
[in,out]attrUnused
[in]scopeUnused
Returns
-1, this function fails
int pthread_attr_setstackaddr ( pthread_attr_t attr,
void *  stackaddr 
)

If *stackaddr == NULL, then the stack is dynamically allocated with malloc(). No two running threads may operate on the same stack. The stack of a zombie thread (i.e. a non-detached thread that exited but was not yet joined) may in theory be reused even before joining, though there might be problems if the stack was preempted before pthread_exit() completed.

Parameters
[in,out]attrAttribute set to operate on.
[in]stackaddrStatic stack to use, or NULL for dynamic allocation.
Returns
0, this invocation cannot fail
int pthread_attr_setstacksize ( pthread_attr_t attr,
size_t  stacksize 
)

If you use pthread_attr_getstackaddr() to assign a static stack, then you must use this function to set the size of the stack. In case of dynamic memory allocation this overrules the default value.

Parameters
[in,out]attrAttribute set to operate on
[in]stacksizeSize of the stack of the new thread. Supply 0 to use the default value.
Returns
0, this invocation cannot fail.