I tried to test an example of C++11 threads in Eclipse. But I got this message when running the program:
terminate called after throwing an instance of 'std::system_error' what(): Operation not permitted'
My system: ubuntu + gcc 4.7
Program:
#include <iostream>
#include <thread>
void worker()
{
std::cout << "hello from worker" << std::endl;
}
int main(int argc, char **argv)
{
std::thread t(worker);
t.join();
}
...and yes, I put -std=c++11
and -pthread
inside C/C++ Build -> Settings -> Tool Settings -> Cross G++ Compiler -> Miscellaneous -> Other Flags
.
Any comments?
-pthread
flag is not present on the command line and you have other versions of libstdc++ installed. So make sure that flag is really being passed to your compiler – Mat-pthread
(or your GCC install is borked) – Mat-pthread
is passed to compiler, because I put it in the same place that I put-std=c++11
, and the code won't be compiled when I did not put-std=c++11
. A more strange thing is that the code works correctly when I compile it from command line manually. – melmi-pthread
isn't used (even if you only have one libstdc++ installed). Make sure-pthread
is used for the compiler command and the linker command. Otherwise libpthread.so won't be linked to and threads cannot be launched at runtime. – Jonathan Wakely