#include #include #include #include // https://en.cppreference.com/w/cpp/thread/thread // https://en.cppreference.com/w/cpp/thread/mutex // https://en.cppreference.com/w/cpp/thread/condition_variable std::mutex mtx; std::condition_variable cv; bool ready = false; void worker() { std::unique_lock lock(mtx); cv.wait(lock, [] { return ready; }); // Wait until 'ready' is set to true std::cout << "Daemon process woke up!" << std::endl; } int main() { std::thread daemon(worker); std::this_thread::sleep_for(std::chrono::seconds(5)); { std::lock_guard lock(mtx); ready = true; } cv.notify_one(); daemon.join(); return 0; }