先决条件: 多线程
null
语法:
// 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(): 它用于获取线程堆栈大小。stacksize属性提供分配给线程堆栈的最小堆栈大小。当成功运行时,它给出0,否则给出任何值。
第一个论点—— 它采用pthread属性。 第二个论点—— 它接受一个变量并给出线程属性的大小。
pthread_attr_setstacksize(): 它用于设置新线程堆栈大小。stacksize属性提供分配给线程堆栈的最小堆栈大小。当成功运行时,如果错误给出任何值,它将给出0。
第一个论点—— 它采用pthread属性。 第二个论点—— 它采用新堆栈的大小(字节)
#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" , 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" , stksize); return 0; } |
输出:
Current stack size - > 4196464 New stack size-> 320000034
对于编译,请使用gcc程序名称。c-lpthread 本文由 德万舒阿加瓦尔 .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 贡献极客。组织 或者把你的文章寄到contribute@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。
如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END