【发布时间】:2015-08-20 05:09:04
【问题描述】:
我有一个需要并行化的伪代码:
int thread_count=8;
for(int i=1;i<100000;i++)
{
do_work(i,record);
}
do_work 函数将基于 i 工作并将输出写入记录。现在,我想将这个序列化实现转换为多线程实现;
我知道我可以做类似的事情
int thread_count=8;
for(int i=1;i<100000;i++)
{
boost::thread t1(do_work,i,std::ref(record));
}
但这会创建数以千计的线程,从而损害性能。我相信发布的问题应该是需要多线程的最自然形式,我想知道解决这个问题的标准 c++ 实践是什么......谢谢。
【问题讨论】:
-
您需要可移植的代码还是可以特定于给定的平台/工具集?例如,Windows 上的 VC++ 具有可以帮助完成此类任务的 PPL。
标签: c++ multithreading boost