Why does this program fire std :: system_error?

Possible duplicate:
Why does this simple std :: thread example not work?

code:

#include <iostream> #include <thread> void f() { std::cout << "hi thread" << std::endl; } int main() { std::thread t(f); std::cout << "hi" << std::endl; t.join(); } 

Question:

 $ g++ -o thread_test thread_test.cpp -std=c++0x $ ./thread_test terminate called after throwing an instance of 'std::system_error' what(): Operation not permitted Abortado 

โ€œAbortadoโ€ means โ€œinterruptedโ€ in my locale.

+4
source share
1 answer

You should associate it with pthread :

 g++ -o thread_test thread_test.cpp -std=c++0x -lpthread 
For implementation

libstdc++ std::thread needs to associate applications with libpthread , otherwise they will throw std::system_error when trying to create a thread.

+9
source

Source: https://habr.com/ru/post/1447052/


All Articles