我有一個問題(段錯誤)在C++ 11中運行多線程代碼。這是代碼:併發環境中的C++ 11 std :: vector
#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;
}
而且這裏GDB回溯:http://pastebin.com/5b5TN70c
有什麼錯呢?
請參閱hmjds回答我的評論和不BL indly複製他的代碼。 – inf 2013-02-14 22:06:56