how to declare a vector of thread

久未见 提交于 2019-12-02 08:45:10

Try this:

#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(); 
}

finally I can solve the problem with this change in my code...

workers.emplace_back(thread{ [&]() {
    calcIterThread(ref(res), inicio, fin, i);
}});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!