The TRF House of Software

timer-service blurb

The idea here is to use alarm(3) to create a simple multiple-timer service. Multiple timers are identified by timer IDs, and a function is associated with each timer. When a timer expires, the correspondent function is called with the ID of the expired timer as the argument.

The timer ID is a "void *" value, so pointers may be used as timer IDs, and the number of concurrent outstanding timers is limited only by available memory.

Note that, since the resolution of alarm(3) is seconds, these timers are necessarily limited to the same resolution. For systems that have setitimer(2), it should be possible to easily modify this code to provide higher-resolution timers.

Extant timers can be cancelled, in which case they do not expire, but are simply deleted.