Hardware Reference
In-Depth Information
int pthread_attr_getstacksize(
pthread_attr_t *attr,
size_t *stacksize
);
attr : The pointer to the attribute to fetch a value from, or to
establish an attribute in.
stacksize : This is a stack size value when setting the attribute,
and a pointer to the receiving size_t variable when fetching
the stack size.
returns : Returns zero if the call is successful; otherwise,
returns an error number (not in errno ).
The following error is possible for pthread_attr_setstacksize(3) :
Error
Description
EINVAL
The stack size is less than PTHREAD_STACK_MIN (16,384) bytes.
The Linux man page further states:
On some systems, pthread_attr_setstacksize() can fail with the error
EINVAL if stack size is not a multiple of the system page size.
The following simple example obtains the system default stack size and increases it
by 8 MB:
pthread_attr_t attr;
size_t stksiz;
pthread_attr_init(&attr); // Initialize attr
pthread_attr_getstacksize (&attr,&stksiz); // Get stack size
stksiz += 8
1024; // Add 8 MB
pthread_attr_setstacksize(&attr,stksiz); // Set stack size
1024
The system default is provided by the initialization of attr . Then it is a matter of
“getting” a value out of the attr object, and then putting in a new stack size in the call to
pthread_attr_setstacksize() .
Note that this set of operations has simply prepared the attributes object attr for use
in a pthread_create() call. The attribute takes effect in the new thread, when the thread
is actually created:
pthread_attr_t attr;
...
rc = pthread_create(&tid,&attr,my_thread,0);
 
Search WWH ::




Custom Search