c++多线程join使用

2021/12/5 20:48:26

本文主要是介绍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");
}

结果:
在这里插入图片描述



这篇关于c++多线程join使用的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程