Standards / Extensions | C or C++ | Dependencies |
---|---|---|
Single UNIX Specification, Version 3 |
both | z/OS V1R9 |
#define _UNIX03_THREADS
#include <pthread.h>
int pthread_attr_getstack(const pthread_attr_t *__restrict__ attr,
void ** __restrict__ addr, size_t * __restrict__ size);
The pthread_attr_getstack() function gets both the base (lowest addressable) storage address and size of the initial stack segment from a thread attribute structure and stores them into addr and size respectively.
attr is a pointer to a thread attribute object initialized by pthread_attr_init().
addr is a pointer to the user-defined location where this function will place the base address of the initial stack segment.
size points to the user-defined location where this function will store the size of the initial stack segment.
If successful, pthread_attr_getstack() returns 0; otherwise it returns an error number.
⁄* CELEBP69 *⁄
⁄* Example using SUSv3 pthread_attr_getstack() interface *⁄
#define _UNIX03_THREADS 1
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <limits.h>
#include <errno.h>
int main(void)
{
pthread_attr_t attr;
int rc;
void *mystack;
size_t mystacksize = 2 * PTHREAD_STACK_MIN;
if (pthread_attr_init(&attr) == -1) {
perror("error in pthread_attr_init");
exit(1);
}
⁄* Get a big enough stack and align it on 4K boundary. *⁄
mystack = malloc(PTHREAD_STACK_MIN * 3);
if (mystack != NULL) {
printf("Using PTHREAD_STACK_MIN to align stackaddr %x.\n", mystack);
mystack = (void *)((((long)mystack + (PTHREAD_STACK_MIN - 1)) ⁄
PTHREAD_STACK_MIN) * PTHREAD_STACK_MIN);
} else {
perror("Unable to acquire storage.");
exit(2);
}
printf("Setting stackaddr to %x\n", mystack);
printf("Setting stacksize to %x\n", mystacksize);
rc = pthread_attr_setstack(&attr, mystack, mystacksize);
if (rc != 0) {
printf("pthread_attr_setstack returned: %d\n", rc);
printf("Error: %d, Errno_Jr: %08x\n", errno, __errno2());
exit(3);
} else {
printf("Set stackaddr to %x\n", mystack);
printf("Set stacksize to %x\n", mystacksize);
}
rc = pthread_attr_destroy(&attr);
if (rc != 0) {
perror("error in pthread_attr_destroy");
printf("Returned: %d, Error: %d\n", rc, errno);
printf("Errno_Jr: %x\n", __errno2());
exit(4);
}
exit(0);
}