#include #include #include #include long SmartScheduleInterval = 1; /* ms */ long SmartScheduleTime = 0; static void SmartScheduleTimer(int sig) { if (sig != 0) SmartScheduleTime += SmartScheduleInterval; } void SmartScheduleStartTimer(void) { struct itimerval timer; timer.it_interval.tv_sec = 0; timer.it_interval.tv_usec = SmartScheduleInterval * 1000; timer.it_value.tv_sec = 0; timer.it_value.tv_usec = SmartScheduleInterval * 1000; setitimer(ITIMER_REAL, &timer, 0); } int main() { /* Set up the timer signal function */ struct sigaction act; act.sa_handler = SmartScheduleTimer; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGALRM); if (sigaction(SIGALRM, &act, 0) < 0) { perror("sigaction failed"); return -1; } /* start timer */ SmartScheduleStartTimer(); /* Loop forever, doing tests which should always succeed, with lots of signals */ int x = 0; int i = 0; while (1) { x = i; int j = x; if (j != i) { printf("failed: %d isn't equal to %d, apparently\n", i, j); break; } i++; } return 0; }