John Cowan wrote on 2003-01-30 20:36 UTC:
> > As far as I remember in the code, and in practice,
> > time_t was just a cute way to encode a date;
> > nothing more.
> You didn't routinely subtract two time_t values to get elapsed time in seconds?

For that purpose, having a leap-second-free second count is not the only
requirement. The far more important requirement is that you use a clock
that can't be adjusted by the sys-admins or by time daemons, and that is
available from startup, even before the system learns about UTC over
some external channel.

For this reason, POSIX offers today two separate clocks:

  CLOCK_REALTIME   is supposed to give the system's best available
                   approximation of UTC (that's what you want to
                   convert to hh:mm:ss timestamps and local time)

  CLOCK_MONOTONIC  is supposed to progress with the system's best
                   available approximation of the SI second (that's
                   what you want to use for measuring time intervals)

If you know TAI from boot-time, you can feed that into CLOCK_MONOTONIC,
but it can equivalently also just be the number of seconds since
power-up. If you have a reference clock, you can frequency control
CLOCK_MONOTONIC, but you must not phase-control it.



Markus Kuhn, Computer Lab, Univ of Cambridge, GB | __oo_O..O_oo__

Reply via email to