C++中的线程

#include <iostream>
#include <string>
#include <thread>

static bool doWokerFlag = true;

void DoWoker()
{
	using namespace std::literals::chrono_literals;

	while (doWokerFlag)
	{
		std::cout << "do working..." << std::endl;
		std::this_thread::sleep_for(1s);
	}
	std::cout << "work done!" << std::endl;
}

int main()
{
	std::thread workder(DoWoker);

	std::cin.get();
	doWokerFlag = false;
	workder.join();

	std::cin.get();
	return 0;
}

  

posted @ 2020-11-18 23:49  xnuwu  阅读(134)  评论(0编辑  收藏  举报