#include <iostream>
#include <thread>
static bool s_Finished = false;
void DoWork()
{
using namespace std::literals::chrono_literals;
std::cout << "DoWork thread id = " << std::this_thread::get_id() << std::endl;
while (!s_Finished)
{
std::cout << "Working..." << std::endl;
std::this_thread::sleep_for(1s);
}
}
int main(void)
{
std::thread worker(DoWork);
std::cin.get();
s_Finished = true;
worker.join();
std::cout << "Finished!" << std::endl;
std::cout << "Another thread id = " << std::this_thread::get_id() << std::endl;;
std::cin.get();
}
【Cherno的C++视频】Threads in C++
最新推荐文章于 2024-09-16 16:07:55 发布