#include <iostream>
#include <thread>
using namespace std;
class TyThread
{
public:
TyThread(std::thread &t) :m_thread(t)
{
}
~TyThread()
{
if (m_thread.joinable())
{
m_thread.join();
}
}
TyThread(const TyThread &o) = delete;
TyThread &operator=(const TyThread &o) = delete;
protected:
private:
std::thread &m_thread;
};
void Test()
{
cout << "进入Test()\n";
this_thread::sleep_for(chrono::seconds(10));
cout << "Test():hello world!\n";
}
void palyx()
{
std::thread t(Test);
TyThread tythread(t);
}
void main()
{
palyx();
system("pause");
}
结果:
版权声明:本文为FairLikeSnow原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。