Returns zero after completing successfully. Any other returned value indicates that an error occurred. If the following condition occurs, the function fails and returns the corresponding value.
This example shows how to create a thread with a custom stack address.
#include <pthread.h> pthread_attr_t tattr; pthread_t tid; int ret; void *stackbase; stackbase = (void *) malloc(size); /* initialized with default attributes */ ret = pthread_attr_init(&tattr); /* setting the base address in the attribute */ ret = pthread_attr_setstackaddr(&tattr, stackbase); /* only address specified in attribute tattr */ ret = pthread_create(&tid, &tattr, func, arg);
This example shows how to create a thread with both a custom stack address and a custom stack size.
#include <pthread.h> pthread_attr_t tattr; pthread_t tid; int ret; void *stackbase; int size = PTHREAD_STACK_MIN + 0x4000; stackbase = (void *) malloc(size); /* initialized with default attributes */ ret = pthread_attr_init(&tattr); /* setting the size of the stack also */ ret = pthread_attr_setstacksize(&tattr, size); /* setting the base address in the attribute */ ret = pthread_attr_setstackaddr(&tattr, stackbase); /* address and size specified */ ret = pthread_create(&tid, &tattr, func, arg);