我这里已经明白了是因为线程不能被复制#include <iostream>#include <thread>#include <vector>using namespace std;void Func() { cout << "hello world" << endl;
}int main() { vector<thread> tmp; for (int i = 0; i < 5; i++)
{
tmp[i] = thread(Func);
} for (auto it : tmp)
{ //
}
}于是我尝试使用迭代器像这样#include <iostream>#include <thread>#include <vector>using namespace std;void Func() { cout << "hello world" << endl;
}int main() { vector<thread> tmp; for (int i = 0; i < 5; i++)
{
tmp[i] = thread(Func);
} for (auto it = tmp.begin(); it != tmp.end(); it++)
{
it->join();
}
}但是运行结果得到段错误,请问是为什么
添加回答
举报
0/150
提交
取消