10.6 POSIX:TMR Timer Implementation
POSIX:TMR timers have several advantages over POSIX:XSI timers. A program can create several POSIX:TMR timers for a given clock such as
. The timers have a
greater resolution since values are given to the nearest nanosecond rather than the
microsecond. The program can specify which signal is delivered for each timer, and the signal handler can determine which timer generated the signal. Also, the signals generated by the timers are queued, and the program can determine when signals have been lost due to overruns.
of multiple timers of Section 10.4 with POSIX:TMR timers are possible. The simplest method is to use one timer and make minor changes in the data types to accommodate the higher resolution. Alternatively, a separate POSIX:TMR timer can implement each software timer. Starting and stopping a timer and handling the timer signal are independent of the other timers, so the only shared structure is the event queue. The
object might have to be reorganized. There may be a limit to the number of timers that are supported for each process given by the constant
. If the number of timers needed is small, this method would be the
to implement. A third approach is to use a single POSIX:TMR timer but modify the method of implementation to make the timing more accurate.
One of the problems with the original timer implementation of this chapter is that there can be a significant amount of timer drift, as discussed in Section 9.6. This
can be virtually eliminated by the use of absolute time rather than relative time. Instead of storing the times relative to the
timer in the active array, store the absolute time of expiration. This approach will probably require 64 bits for each entry, perhaps a
. Alternatively, use a
to store the number of microseconds or nanoseconds since the Epoch. This has the advantage of simplifying comparisons of time, but times must be converted to a
when timers are set.