The native 10ms ticking rate can be achieved with the select() system call, which can be used as a fairly portable way to sleep. For some reason, all other system calls (setitimer(), nanosleep(), etc.) seem to be unable to bl ock for less than two clock ticks (20 milliseconds).
When using select() in Linux, the timeout value passed to select() is round ed up to the nearest tick (10 milliseconds on desktop POSIX). The timeout c annot be too short, because the system might choose to busy-wait for very s hort timeouts. Also according to the man pages, the function select() on P OSIX modifies the timeout argument to reflect the amount of time not slept. Most other implementations do not do this. This quirk is handled in a port able way by always setting the microsecond part of the structure before each select() c all:
struct timeval timeout = { 0 }; . . . while (1) { // do timed processing at 10ms interval... timeout.tv_usec = 10000UL; /* set the desired tick interval */ select(0, 0, 0, 0, &timeout); /* sleep for the full tick */ }
Miro Samek state-machine.com