c++ - 如何使用 C++ boost 库为特定线程定义堆栈大小?

标签 c++ multithreading c++11 boost

我需要增加 boost::thread 对象的堆栈大小。线程的任务是存储大量的 3D 点,这是递归实现的,因此在堆栈上需要相当多的内存空间。

int main(int argc, char* argv[]) {
    Flashlight *flashlight = new Flashlight();
    flashlight->thread_group = new boost::thread_group();
    boost::thread::attributes attrs;
    attrs.set_stack_size(16*1024*1024);
    flashlight->orbslam_thread = new boost::thread(attrs, boost::bind(&Flashlight::orbslam_loop, flashlight));
    flashlight->thread_group->add_thread(flashlight->orbslam_thread);
    // initializing some more threads ...
    flashlight->thread_group->join_all();
    return 0;
}

A.) 我是否在上面列出的代码中正确地将线程的堆栈大小增加到 16MB?

B.) 是否有可能以某种方式读取 boost::thread 对象的属性,尤其是当前堆栈大小?

最佳答案

是的,您已将堆栈大小设置为 16M。这为您提供了堆栈大小。

std::cout << attrs.get_stack_size() << std::endl;

关于c++ - 如何使用 C++ boost 库为特定线程定义堆栈大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53163017/

相关文章:

c# - 从 C# 调用不安全的 C++ 时出现 System.AccessViolationException

c# - 实现多线程后与数据库的连接丢失

java - Intellij IDEA 线程问题

ios - 如果使用 [NSOperation start] 手动执行,NSOperation 将在哪个线程上运行?

c++ - 如何编写具有不同数量的信息参数的 C++ 断言宏?

c++ - 如何处理异常以便我的程序仍然运行?

c++ - 如何捕获浏览的url?

c++ - 如何在 C++ 中创建和使用实例数组?

c++ - 在 C++ 中使用 typedef 声明结构

c++ - 包装非类型模板常量以避免混合相同类型的参数