一:解决什么问题
join:主线程等待子线程执行结束
解决了困扰我已久的
wait在notify前面的时候,线程怎么join的问题
二:答案:在析构函数里join
三:测试:不在析构函数里join的报错
#include <thread>
#include <iostream>
#include <chrono>
void func1()
{
std::cout << "hello world" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(2));
std::cout << "enjoy" << std::endl;
}
int main()
{
std::thread th1(func1);
th1.join();
std::cout << "test" << std::endl;
return 0;
}