StromanStroman 2023-02-28 09:29 采纳率: 40.9%
浏览 28
已结题

如何获取boost::thread_group返回值?

请问在boost::thread_group中,我如何获取每个子线程任务的返回值?
boost版本:1.79.0
操作系统版本:Windows11
编译器:VS2022

  • 写回答

2条回答 默认 最新

  • 元气少女缘结神 2023-02-28 10:22
    关注

    没懂,你是要区分子线程?

    #include <boost/thread.hpp>
    #include <boost/bind.hpp>
    #include <iostream>
    void fun(int i) {
        std::cout << "fun:" << i << std::endl;
    }
    int main() {
        boost::thread_group threads;
        for (auto i = 0;i < 10;i++) {
            threads.create_thread(boost::bind(fun, i));
        }
        threads.join_all();
     
        return 0;
    }
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 3月8日
  • 已采纳回答 2月28日
  • 创建了问题 2月28日