我有一个问题(segfault)在C++ 11中运行多线程代码.这是代码:
#include <vector>
#include <thread>
std::vector<int> values;
int i;
void values_push_back()
{
values.push_back(i);
}
int main()
{
while(true)
{
std::vector<std::thread> threads;
for(i=0; i<10; ++i)
{
std::thread t(values_push_back);
threads.push_back(std::move(t));
}
for(i=0; i<10; ++i)
threads[i].join();
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这里是gdb上的回溯:http://pastebin.com/5b5TN70c
这有什么不对?