gpt4 book ai didi

c++ - 如何使用 pthreads 在 solaris 上增加 c++ 线程堆栈大小?

转载 作者:行者123 更新时间:2023-11-28 07:01:51 25 4
gpt4 key购买 nike

增加 pthreads 默认堆栈大小的最简单方法是什么?有没有办法调整堆大小、进程级别和单个线程级别?如果 new 运算符由于底层内存泄漏而失败,我该如何设置 new 处理程序来处理错误的分配?

最佳答案

What is the easiest way to increase the size of the default stacksize for pthreads?

您可以使用 pthread_attr_setstacksize在创建新线程时设置堆栈大小。堆栈大小不得小于 PTHREAD_STACK_MIN

Is there any way to tune the heapsize as well, process level and individual thread level?

使用 Solaris 编译器,您可以尝试使用 -xpagesize 选项更改页面大小,但您无法调整堆的大小(它将与机器可用的内存一样大) .所有线程只共享一个堆,因此您不能按线程调整它。

If new operator fails because of underlying memory leakage, how do I set new handler to take care of bad allocations?

新的处理程序是一个专门的功能,没有通用的答案,如何使用新的处理程序在很大程度上取决于您的程序的细节。它不能用于修复内存泄漏,一旦内存泄漏就为时已晚,因此您需要首先防止泄漏发生。 (如果您不知道如何编写新的处理程序,那么您可能不需要使用它。)

关于c++ - 如何使用 pthreads 在 solaris 上增加 c++ 线程堆栈大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22320838/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com