我是c ++编程的新手,需要一些帮助来使用带有矢量库的线程库...
首先我按照tutorial
进行操作但编译器(visual studio 2013)向我显示错误,我不知道它是多么正确:
首次宣布职能
change
在主循环中
void Fractal::calcIterThread(vector<vector<iterc>> &matriz, int desdePos, int hastaPos, int idThread){
...
}
感谢任何帮助澄清
答案 0 :(得分:1)
试试这个:
#include <functional>
#include <thread>
#include <vector>
// ...
int numThreads = 10;
std::vector<std::thread> workers;
for (int i = 0; i != numThreads; ++i)
{
workers.emplace_back(calcIterThread, std::ref(res), inicia, fin, i);
}
for (auto & t : workers)
{
t.join();
}
答案 1 :(得分:0)
最后我可以用我的代码中的这个变化解决问题...
workers.emplace_back(thread{ [&]() {
calcIterThread(ref(res), inicio, fin, i);
}});