Hi I am trying to use std::thread
with G++. Here is my test code
#include <thread>
#include <iostream>
int main(int, char **){
std::thread tt([](){ std::cout<<"Thread!"<<std::endl; });
tt.join();
}
It compiles, but when I try to run it the result is:
terminate called after throwing an instance of 'std::system_error'
what(): Operation not permitted
Aborted
My compiler version:
$ g++ --version
g++ (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
What is wrong with my test code?
UPDATE: I use the following command line to compile and run my code.
$ g++ -std=c++0x test.cpp
$ ./a.out
and I tried
$ g++ -std=c++0x -lpthread test.cpp
$ ./a.out
still the same.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…