Multithreaded Programming Guide

Return Values

pthread_attr_setstackaddr() returns zero after completing successfully. Any other return value indicates that an error occurred. If the following condition occurs, the function fails and returns the corresponding value.


The value of base or tattr is incorrect.

This example shows how to create a thread with a custom stack address and size.

#include <pthread.h>

pthread_attr_t tattr;
pthread_t tid;
int ret;
void *stackbase;

/* initialized with default attributes */
ret = pthread_attr_init(&tattr);

/* setting the size of the stack */
ret = pthread_attr_setstacksize(&tattr, size);

/* setting the base address of the stack */
ret = pthread_attr_setstackaddr(&tattr, stackbase);

/* address and size specified */
ret = pthread_create(&tid, &tattr, func, arg);