您好,欢迎来到榕意旅游网。
搜索
您的当前位置:首页c++多线程join使用

c++多线程join使用

来源:榕意旅游网
#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");
}

结果:

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- nryq.cn 版权所有 赣ICP备2024042798号-6

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务