Maybe something like this could work for you:
To compile it:
Code:
#include <iostream>#include <chrono>#include <thread>int main(){ std::thread timer([]() { std::this_thread::sleep_for(std::chrono::seconds(2)); std::cout << "Turning ON" << std::endl; std::this_thread::sleep_for(std::chrono::seconds(4)); std::cout << "Turning OFF" << std::endl; }); std::cout << "Timer started. Will fire in 2 seconds." << std::endl; // Wait for timer to exit timer.join(); return 0;}
Code:
g++ -o timer -pthread -l pthread timer.cpp
Statistics: Posted by deepo — Tue Dec 10, 2024 10:28 pm