Prerequisite : Multithreading
Syntax :
// to get size of stack int pthread_attr_getstacksize(const pthread_attr_t* restrict attr, size_t* restrict stacksize); // to set size of stack 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() { // for takes the size of threads stack size_t stksize; // attribute declaration pthread_attr_t atr; // it gets the threads stack size and give // value in stksize variable pthread_attr_getstacksize(&atr;, &stksize;); // print the current threads stack size printf("Current stack size - > %d\n", stksize); // then set the new threads stack size pthread_attr_setstacksize(&atr;, 320000034); pthread_attr_getstacksize(&atr;, &stksize;); // print the new stack size 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
This article is contributed by Devanshu Agarwal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Thread functions in C/C++
- Print numbers in sequence using thread synchronization
- Get/Set process resource limits in C
- Heap overflow and Stack overflow
- C Program to find direction of growth of stack
- Inter-process Communication using a shared stack
- Stack vs Heap Memory Allocation
- How to get the current position of cursor from output screen in C?
- C/C++ program to find the size of int, float, double and char
- size of char datatype and char array in C
- How does free() know the size of memory to be deallocated?
- How to print size of array parameter in C++?
- How to find size of array in C/C++ without using sizeof ?
- Extended Integral Types (Choosing the correct integer size in C/C++)
- C Program to find size of a File
- Why is the size of an empty class not zero in C++?
- Count number of unique Triangles using STL | Set 1 (Using set)
- Pointers in C and C++ | Set 1 (Introduction, Arithmetic and Array)
- Exception handling and object destruction | Set 1
- Static and Dynamic Libraries | Set 1

