要在C中获取和设置线程属性的堆栈大小,我们使用以下线程属性:
用于获取线程堆栈大小。stacksize属性给出了分配给线程堆栈的最小堆栈大小。如果成功运行,则返回0,否则返回任何值。
它接受两个参数:
pthread_attr_getstacksize(pthread_attr_t *attr, size_t *stacksize)
立即学习“C语言免费学习笔记(深入)”;
用于设置新的线程堆栈大小。stacksize属性给出了分配给线程堆栈的最小堆栈大小。如果成功运行,则返回0,否则返回任何值。
它接受两个参数:
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
以上就是获取和设置C语言中线程属性的堆栈大小的详细内容,更多请关注php中文网其它相关文章!
C语言怎么学习?C语言怎么入门?C语言在哪学?C语言怎么学才快?不用担心,这里为大家提供了C语言速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号