Something went wrong. Try again.
A Tour of C++ for experienced programmers, as if C++26 is the only version that ever existed.
Something went wrong. Try again.
123456789101112131415161718192021// examples/ch25/ch25_stop_token.cpp#include <iostream>#include <thread>#include <stop_token>#include <chrono>
void work(std::stop_token st) { while (!st.stop_requested()) { std::cout << "working" << std::endl; std::this_thread::sleep_for(std::chrono::milliseconds(10)); } std::cout << "stop requested" << std::endl;}
int main() { std::jthread t(work); std::this_thread::sleep_for(std::chrono::milliseconds(30)); t.request_stop(); return 0;}