C based timer
#include <iostream>
- include <unistd.h>
<using namespace std;
// Define the callback function
void callback() {
cout << "Timer callback called!" << endl;
}
// Create the timer
timer_t timer;
struct sigevent sigev;
// Set up the timer
sigev.sigev_notify = SIGEV_THREAD;
sigev.sigev_notify_function = callback;
sigev.sigev_value.sival_ptr = &timer;
timer_create(CLOCK_REALTIME, &sigev, &timer);
// Start the timer
timer_settime(timer, 0, new itimerspec{1, 0}, NULL);
// Wait for the timer to expire
pause();
// Delete the timer
timer_delete(timer);