Get the stack size and set the stack size of thread attribute in C
Prerequisite : Multithreading
Syntax :
int pthread_attr_getstacksize( const pthread_attr_t* restrict attr,
size_t * restrict stacksize);
int pthread_attr_setstacksize(pthread_attr_t* attr, size_t stacksize);
|
.
pthread_attr_getstacksize() :
It is use for get threads stack size. The stacksize attribute gives the minimum stack size allocated to threads stack. When successfully run then it gives 0 otherwise gives any value.
First argument – It takes pthread attribute.
Second argument – It takes a variable and give the size of the thread attribute.
pthread_attr_setstacksize() :
It is use for set new threads stack size. The stacksize attribute gives the minimum stack size allocated to threads stack. When successfully run then it gives 0 otherwise if error gives any value.
First argument – It takes pthread attribute.
Second argument – It takes the size of new stack (In bytes)
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
int main()
{
size_t stksize;
pthread_attr_t atr;
pthread_attr_getstacksize(&atr, &stksize);
printf ( "Current stack size - > %d\n" , stksize);
pthread_attr_setstacksize(&atr, 320000034);
pthread_attr_getstacksize(&atr, &stksize);
printf ( "New stack size-> %d\n" , stksize);
return 0;
}
|
Output :
Current stack size - > 4196464
New stack size-> 320000034
For compile use gcc program_name.c -lpthread
Last Updated :
22 Sep, 2017
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...