运行以下程序:
#include <thread>
#include <iostream>
void my_thread_func()
{
std::cout<<"hello"<<std::endl;
}
int main()
{
std::thread t(my_thread_func);
}
提示错误为:
terminate called without an active exception hello 已放弃
考虑应该是主线程结束了子线程还没有结束导致的。
应该在main函数中增加:
t.join();