Correct way to pause & resume an std::thread
问题 I am using an std::thread in my C++ code to constantly poll for some data & add it to a buffer. I use a C++ lambda to start the thread like this: StartMyThread() { thread_running = true; the_thread = std::thread { [this] { while(thread_running) { GetData(); } }}; } thread_running is an atomic<bool> declared in class header. Here is my GetData function: GetData() { //Some heavy logic which needs to be executed in a worker thread } Next I also have a StopMyThread function where I set thread