#pragma once #include #include #include class Waiter { public: template bool wait_for(std::chrono::duration const &time) const { std::unique_lock lock(m); return !cv.wait_for(lock, time, [&] { return terminate; }); } void kill() { std::unique_lock lock(m); terminate = true; cv.notify_all(); } void revive() { std::unique_lock lock(m); terminate = false; } private: mutable std::condition_variable cv; mutable std::mutex m; bool terminate = false; };