【发布时间】:2014-04-25 01:55:58
【问题描述】:
我环顾了 Stack Overflow,对此有一些非常好的答案,(我的代码实际上基于 this answer here)但由于某种原因,我的行为很奇怪——应该调用 ls1 次 thread_func ,但在线程退出之前它只运行了 0 到 2 次。似乎 ioService.stop() 在完成之前切断了排队的作业,但据我所知,这不应该发生。下面是相关代码sn-p:
boost::asio::io_service ioService;
boost::asio::io_service::work work(ioService);
boost::thread_group threadpool;
for (unsigned t = 0; t < num_threads; t++)
{
threadpool.create_thread(boost::bind(&boost::asio::io_service::run, &ioService));
}
//Iterate over the dimensions of the matrices
for (unsigned i = 0; i < ls1; i++)
{
ioService.post(boost::bind(&thread_func,i, rs1, rs2, ls2, arr, left_arr, &result));
}
ioService.stop();
threadpool.join_all();
任何帮助将不胜感激,谢谢!
【问题讨论】:
标签: c++ boost boost-asio threadpool boost-thread