pthread_attr_getstacksize() — Get the thread attribute stacksize object
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
POSIX.4a |
both | POSIX(ON) |
Format
#define _OPEN_THREADS
#include <pthread.h>
int pthread_attr_getstacksize(pthread_attr_t *attr, size_t *stacksize);
SUSV3
#define _UNIX03_THREADS
#include <pthread.h>
int pthread_attr_getstacksize(const pthread_attr_t * __restrict__attr,
size_t * __restrict__stacksize);
General description
Gets the value, in bytes, of the stacksize attribute for the thread attribute object, attr, that is created by pthread_attr_init(). This function returns the value in the variable pointed to by stacksize.
You can
use a thread attribute object to manage the characteristics of threads
in your application. It defines the set of values to be used for the
thread during its creation. By establishing a thread attribute object,
you can create many threads with the same set of characteristics,
without defining those characteristics for each thread. You can define
more than one thread attribute object.
Note: An XPLINK
application uses two stacks, an upward-growing stack and a downward-growing
stack. The "stacksize" refers to the size of the downward-growing
stack.
Returned value
If successful, pthread_attr_getstacksize() returns 0 and stores the stacksize attribute value in stacksize.
If unsuccessful, pthread_attr_getstacksize() returns -1.
There are no documented errno values. Use perror() or strerror() to determine the cause of the error.
Special behavior for Single UNIX Specification, Version 3: If unsuccessful, pthread_attr_getstacksize() returns an error number to indicate the error.
Example
CELEBP08
/* CELEBP08 */
#define _OPEN_THREADS
#include <stdio.h>
#include <pthread.h>
int main()
{
pthread_attr_t attr;
size_t size;
if (pthread_attr_init(&attr) == -1) {
perror("error in pthread_attr_init");
exit(1);
}
if (pthread_attr_getstacksize(&attr, &size) == -1) {
perror("error in pthread_attr_getstackstate()");
exit(2);
}
printf("The stack size is %d.\n", (int) size);
if (pthread_attr_destroy(&attr) == -1) {
perror("error in pthread_attr_destroy");
exit(2);
}
exit(0);
}
Output:
The stack size is 524288.