c++报terminate called after throwing an instance of 'std::system_error' what(): Unknown error -1错误

在线程编程时,编译器报

terminate called after throwing an instance of 'std::system_error'
terminate called recursively
  what():  Unknown error -1
Aborted (core dumped)
解决方法:在链接时,加上 -pthread选项。g++ -std=c++11 -pthread thread_demo.cpp -o demo。

clion编译时,会报这种错误。需要在CMakeLists.txt修改编译选项。