我正在阅读来自 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/