Home > Article > Backend Development > Get and set the stack size of thread properties in C language
To get and set the stack size of a thread attribute in C, we use the following thread attribute:
is used to get the thread Stack size. The stacksize attribute gives the minimum stack size allocated to the thread stack. Returns 0 if run successfully, otherwise returns any value.
It accepts two parameters:
pthread_attr_getstacksize(pthread_attr_t *attr, size_t *stacksize)
is used to set the new thread stack size. The stacksize attribute gives the minimum stack size allocated to the thread stack. Returns 0 if run successfully, otherwise returns any value.
It accepts two parameters:
pthread_attr_setstacksize(pthread_attr_t *attr, size_t *stacksize)
Begin Declare stack size and declare pthread attribute a. Gets the current stacksize by pthread_attr_getstacksize() and print it. Set the new stack size by pthread_attr_setstacksize() and get the stack size pthread_attr_getstacksize() and print it. End
#include <stdio.h> #include <stdlib.h> #include <pthread.h> int main() { size_t stacksize; pthread_attr_t a; pthread_attr_getstacksize(&a, &stacksize); printf("Current stack size = %d</p><p>", stacksize); pthread_attr_setstacksize(&a, 67626); pthread_attr_getstacksize(&a, &stacksize); printf("New stack size= %d</p><p>", stacksize); return 0; }
Current stack size = 50 New stack size= 67626
The above is the detailed content of Get and set the stack size of thread properties in C language. For more information, please follow other related articles on the PHP Chinese website!