c - 为什么默认堆栈大小为 0

标签 c pthreads

我正在阅读来自 https://computing.llnl.gov/tutorials/pthreads/ 的线程它说

Default thread stack size varies greatly. The maximum size that can be obtained also varies greatly, and may depend upon the number of threads per node. Both past and present architectures are shown to demonstrate the wide variation in default thread stack size.

然后它列出了几个处理器的一些默认值,但它从来没有为任何处理器说 0。所以我复制粘贴了它的 C 程序并执行了。相关部分是:

   size_t stacksize;     
   pthread_attr_init(&attr);
   pthread_attr_getstacksize (&attr, &stacksize);
   printf("Default stack size = %li\n", stacksize);

我得到输出:

Default stack size = 0

为什么是 0?

最佳答案

属性中的堆栈大小是最小 堆栈大小,很可能为零。我怀疑在那种情况下,使用该属性创建的任何线程都会得到一个合理的默认值,例如 4M。

我们的想法是,如果您想要默认值,请单独保留属性堆栈大小,如果您想将其强制设置为特定的最小值,则将其设置为其他值。

关于c - 为什么默认堆栈大小为 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9340222/

相关文章:

每次使用 pthread 调用方法时创建一个新线程

c - C中Thread函数返回值的查询

c - 线程在加入之前退出

c - c中的函数指针typedef

c - 多重逻辑运算符 || C 中 for 循环中的 (OR) 条件

c - 全局和函数中的不同初始化和符号指针值

将整数值转换为位并将其存储到字符数组中?

Char 与 int 调用约定

c - 不使用 * operator hack-y 方式获取产品

c - 为什么 valgrind 仅通过多次运行程序就报告不同的结果(不可能/仍然可以到达泄漏)?