【问题标题】:Increasing stack size of child threads on solaris for pthreads为 pthread 增加 solaris 上子线程的堆栈大小
【发布时间】:2014-04-17 20:35:27
【问题描述】:

我正在尝试使用以下代码 sn-p 增加 pthread 的堆栈大小:

 size_t newstacksz = 0xf000;
 void * arg = 0;
 int ret = pthread_attr_setstacksize(&attr, newstacksz);
 if (ret == -1) {
   std::cout << "Attempt to increase thread stack size failed, resorting to default" << endl;
   ret = pthread_attr_setstacksize(&attr, 0); // minimum allowable
 }
 pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_JOINABLE);
 pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);  // system-wide contention
 ret = pthread_create(&tid,&attr,thrfn,arg);
 pthread_attr_destroy(&attr);

如果我要创建多个工作线程,我能否估算出每个线程允许的最大堆栈大小?

【问题讨论】:

    标签: c++ multithreading stack pthreads solaris


    【解决方案1】:

    pthreads 没有最大堆栈大小的概念。所以没有办法要求 pthread 给线程“最大允许”堆栈大小。也没有办法向 pthread 询问已知线程集的建议最大允许堆栈大小。

    适合您的特定应用程序的(最大?)堆栈大小取决于许多因素:机器、操作系统、可用内存、预期负载、预期堆栈消耗等,所以真的没有奇怪 pthreads 不能告诉你。我也不能。

    您必须自己弄清楚合适的堆栈大小。

    【讨论】:

      猜你喜欢
      • 2014-04-14
      • 1970-01-01
      • 2020-08-30
      • 2015-11-22
      • 2021-03-17
      • 2010-11-24
      • 2010-09-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多