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; }