#include <iostream>
#include <thread>
void f()
{
std::cout << "hello thread" << std::endl;
}
int main()
{
#include <thread>
void f()
{
std::cout << "hello thread" << std::endl;
}
int main()
{
std::thread t1{f}; // f() 在一个单独的线程中执行
t1.join();
}
}
编译
解决错误
terminate called after throwing an instance of 'std::system_error'
what(): Operation not permitted
Aborted
需使用-pthread
g++ -o hello -pthread -std=c++0x hellothread.cpp