Loading...
Searching...
No Matches
pthread_threading_attr.h File Reference

Thread creation features (attributes). More...

Detailed Description

Thread creation features (attributes).

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).
 
#define PTHREAD_CREATE_DETACHED   (1)
 Create new pthread in detached state.
 
int pthread_attr_init (pthread_attr_t *attr)
 Initialize attributes for a new pthread.
 
int pthread_attr_destroy (pthread_attr_t *attr)
 Destroys an attribute set.
 
int pthread_attr_getdetachstate (const pthread_attr_t *attr, int *detachstate)
 Tells whether to create a new pthread in a detached state.
 
int pthread_attr_setdetachstate (pthread_attr_t *attr, int detachstate)
 Sets whether to create a new pthread in a detached state.
 
int pthread_attr_getguardsize (const pthread_attr_t *attr, size_t *guardsize)
 This function is unused right now, and only exists for POSIX compatibility.
 
int pthread_attr_setguardsize (pthread_attr_t *attr, size_t guardsize)
 This function is unused right now, and only exists for POSIX compatibility.
 
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.
 
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.
 
int pthread_attr_getschedpolicy (const pthread_attr_t *attr, int *policy)
 This function is unused right now, and only exists for POSIX compatibility.
 
int pthread_attr_setschedpolicy (pthread_attr_t *attr, int policy)
 This function is unused right now, and only exists for POSIX compatibility.
 
int pthread_attr_getinheritsched (const pthread_attr_t *attr, int *inherit)
 This function is unused right now, and only exists for POSIX compatibility.
 
int pthread_attr_setinheritsched (pthread_attr_t *attr, int inherit)
 This function is unused right now, and only exists for POSIX compatibility.
 
int pthread_attr_getscope (const pthread_attr_t *attr, int *scope)
 This function is unused right now, and only exists for POSIX compatibility.
 
int pthread_attr_setscope (pthread_attr_t *attr, int scope)
 This function is unused right now, and only exists for POSIX compatibility.
 
int pthread_attr_getstackaddr (const pthread_attr_t *attr, void **stackaddr)
 Query assigned stack for new pthread.
 
int pthread_attr_setstackaddr (pthread_attr_t *attr, void *stackaddr)
 Set address of the stack to use for the new pthread.
 
int pthread_attr_getstacksize (const pthread_attr_t *attr, size_t *stacksize)
 Query set stacksize for new pthread.
 
int pthread_attr_setstacksize (pthread_attr_t *attr, size_t stacksize)
 Set the stack size for the new pthread.
 
int pthread_attr_getstack (pthread_attr_t *attr, void **stackaddr, size_t *stacksize)
 Query set stacksize for new pthread.
 
int pthread_attr_setstack (pthread_attr_t *attr, void *stackaddr, size_t stacksize)
 Set address and stack size of the stack to use for the new pthread.
 

Macro Definition Documentation

◆ PTHREAD_CREATE_DETACHED

#define PTHREAD_CREATE_DETACHED   (1)

Create new pthread in detached state.

Definition at line 45 of file pthread_threading_attr.h.

◆ PTHREAD_CREATE_JOINABLE

#define PTHREAD_CREATE_JOINABLE   (0)

Create new pthread as joinable (default).

Definition at line 44 of file pthread_threading_attr.h.

Function Documentation

◆ pthread_attr_destroy()

int pthread_attr_destroy ( pthread_attr_t attr)

Destroys an attribute set.

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

Returns
0, since this a no-op that cannot fail

◆ pthread_attr_getdetachstate()

int pthread_attr_getdetachstate ( const pthread_attr_t attr,
int *  detachstate 
)

Tells whether to create a new pthread in a detached state.

Parameters
[in]attrAttribute set to query.
[out]detachstateEither PTHREAD_CREATE_JOINABLE or PTHREAD_CREATE_DETACHED.
Returns
0, the invocation cannot fail

◆ pthread_attr_getguardsize()

int pthread_attr_getguardsize ( const pthread_attr_t attr,
size_t *  guardsize 
)

This function is unused right now, and only exists for POSIX compatibility.

Parameters
[in]attrUnused
[out]guardsizeUnused
Returns
-1, this function fails

◆ pthread_attr_getinheritsched()

int pthread_attr_getinheritsched ( const pthread_attr_t attr,
int *  inherit 
)

This function is unused right now, and only exists for POSIX compatibility.

Parameters
[in]attrUnused
[out]inheritUnused
Returns
-1, this function fails

◆ pthread_attr_getschedparam()

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.

Parameters
[in]attrUnused
[out]paramUnused
Returns
-1, this function fails

◆ pthread_attr_getschedpolicy()

int pthread_attr_getschedpolicy ( const pthread_attr_t attr,
int *  policy 
)

This function is unused right now, and only exists for POSIX compatibility.

Parameters
[in]attrUnused
[out]policyUnused
Returns
-1, this function fails

◆ pthread_attr_getscope()

int pthread_attr_getscope ( const pthread_attr_t attr,
int *  scope 
)

This function is unused right now, and only exists for POSIX compatibility.

Parameters
[in]attrUnused
[out]scopeUnused
Returns
-1, this function fails

◆ pthread_attr_getstack()

int pthread_attr_getstack ( pthread_attr_t attr,
void **  stackaddr,
size_t *  stacksize 
)

Query set stacksize for new pthread.

Parameters
[in]attrAttribute set to query.
[out]stackaddrPointer to previously assigned stack, or NULL for dynamic allocation.
[out]stacksizeAssigned or default stack size, resp.
Returns
0, this invocation cannot fail

◆ pthread_attr_getstackaddr()

int pthread_attr_getstackaddr ( const pthread_attr_t attr,
void **  stackaddr 
)

Query assigned stack for new pthread.

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

◆ pthread_attr_getstacksize()

int pthread_attr_getstacksize ( const pthread_attr_t attr,
size_t *  stacksize 
)

Query set stacksize for new pthread.

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

◆ pthread_attr_init()

int pthread_attr_init ( pthread_attr_t attr)

Initialize attributes for a new pthread.

See also
pthread_create()

A zeroed out attr is initialized.

Parameters
[in,out]attrStructure to initialize
Returns
0, invocation cannot fail

◆ pthread_attr_setdetachstate()

int pthread_attr_setdetachstate ( pthread_attr_t attr,
int  detachstate 
)

Sets whether to create a new pthread in a detached state.

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.

◆ pthread_attr_setguardsize()

int pthread_attr_setguardsize ( pthread_attr_t attr,
size_t  guardsize 
)

This function is unused right now, and only exists for POSIX compatibility.

Parameters
[in,out]attrUnused
[in]guardsizeUnused
Returns
-1, this function fails

◆ pthread_attr_setinheritsched()

int pthread_attr_setinheritsched ( pthread_attr_t attr,
int  inherit 
)

This function is unused right now, and only exists for POSIX compatibility.

Parameters
[in,out]attrUnused
[in]inheritUnused
Returns
-1, this function fails

◆ pthread_attr_setschedparam()

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.

Parameters
[in,out]attrUnused
[in]paramUnused
Returns
-1, this function fails

◆ pthread_attr_setschedpolicy()

int pthread_attr_setschedpolicy ( pthread_attr_t attr,
int  policy 
)

This function is unused right now, and only exists for POSIX compatibility.

Parameters
[in,out]attrUnused
[in]policyUnused
Returns
-1, this function fails

◆ pthread_attr_setscope()

int pthread_attr_setscope ( pthread_attr_t attr,
int  scope 
)

This function is unused right now, and only exists for POSIX compatibility.

Parameters
[in,out]attrUnused
[in]scopeUnused
Returns
-1, this function fails

◆ pthread_attr_setstack()

int pthread_attr_setstack ( pthread_attr_t attr,
void *  stackaddr,
size_t  stacksize 
)

Set address and stack size of the stack to use for the new pthread.

This function requires setting the address as well as the size since only setting the address will make the implementation on some architectures impossible. 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.
[in]stacksizeSize of the stack of the new thread. Supply 0 to use the default value.
Returns
0, this invocation cannot fail

◆ pthread_attr_setstackaddr()

int pthread_attr_setstackaddr ( pthread_attr_t attr,
void *  stackaddr 
)

Set address of the stack to use for the new pthread.

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

◆ pthread_attr_setstacksize()

int pthread_attr_setstacksize ( pthread_attr_t attr,
size_t  stacksize 
)

Set the stack size for the new pthread.

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.