lve*_*lla 4 c++ c++11 stdthread
码:
#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();
}
Run Code Online (Sandbox Code Playgroud)
问题:
$ 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
Run Code Online (Sandbox Code Playgroud)
"Abortado"在我的语言环境中意为"中止".
你应该把它链接到pthread:
g++ -o thread_test thread_test.cpp -std=c++0x -lpthread
Run Code Online (Sandbox Code Playgroud)
libstdc++的std::thread实现需要你链接你的应用程序libpthread,否则他们会std::system_error在你尝试创建一个线程时抛出一个.