Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <chrono>
- #include <iostream>
- #include <thread>
- bool stopAtTheCrossroad()
- {
- std::cout << std::this_thread::get_id();
- char ch;
- std::cin.get(ch);
- if (ch == 'q')
- return true;
- return false;
- }
- int main()
- {
- bool exit{false};
- std::thread th([&exit]() { exit = stopAtTheCrossroad(); });
- for (int i = 0; true; ++i)
- {
- std::cout << "iter " << i + 1 << ": \tprint, thread id = " << std::this_thread::get_id() << std::endl;
- std::this_thread::sleep_for(std::chrono::milliseconds(300));
- if (exit)
- break;
- }
- th.join();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement