要在C中获取和设置线程属性的堆栈大小,我们使用以下线程属性:
pthread_attr_getstacksize()
用于获取线程堆栈大小。stacksize属性给出了分配给线程堆栈的最小堆栈大小。如果成功运行,则返回0,否则返回任何值。
它接受两个参数:
pthread_attr_getstacksize(pthread_attr_t *attr, size_t *stacksize)
立即学习“C语言免费学习笔记(深入)”;
第一个参数是pthread属性。第二个参数是线程属性的大小。
pthread_attr_setstacksize()
用于设置新的线程堆栈大小。stacksize属性给出了分配给线程堆栈的最小堆栈大小。如果成功运行,则返回0,否则返回任何值。
它接受两个参数:
pthread_attr_setstacksize(pthread_attr_t *attr, size_t *stacksize)
第一个参数是pthread属性。第二个参数是以字节为单位的新堆栈大小。
算法
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 #include #include int main() { size_t stacksize; pthread_attr_t a; pthread_attr_getstacksize(&a, &stacksize); printf("Current stack size = %d", stacksize); pthread_attr_setstacksize(&a, 67626); pthread_attr_getstacksize(&a, &stacksize); printf("New stack size= %d
", stacksize); return 0;}
登录后复制
输出
Current stack size = 50New stack size= 67626
登录后复制
以上就是获取和设置C语言中线程属性的堆栈大小的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2581965.html