[vlc-devel] CLOCK_MONOTONIC

Rémi Denis-Courmont rem at videolan.org
Sun Sep 16 09:54:46 CEST 2007


Le Sunday 16 September 2007 02:29:10 Rafaël Carré, vous avez écrit :
> For this clock, the value returned by clock_gettime() represents the
> amount of time (in seconds and nanoseconds) since an unspecified point
> in the past (for example, system start-up time, or the Epoch). This
> point does not change after system start-up time. The value of the
> CLOCK_MONOTONIC clock cannot be set via clock_settime(). This function
> shall fail if it is invoked with a clock_id argument of CLOCK_MONOTONIC.
> [Option End]
>
> So the starting value may, or may not be the Epoch.

The value cannot be the Epoch. CLOCK_REALTIME is the Epoch. CLOCK_REALTIME can 
go backward (through settimeofday/clock_settime), and CLOCK_MONOTONIC cannot, 
by definition. As such, CLOCK_MONOTONIC cannot be the Epoch (it could have 
the same value at any given time, by pure accident only).

In practice CLOCK_MONOTONIC is the system uptime, much like GetTickCount() On 
Win32, or times() on old Unices. Depending on OSes and versions, it does or 
does not include suspend time.

> this causes __vlc_cond_wait() to immediately timeout instead of after 1
> second, because the time elapsed since epoch is always more than the
> time elapsed since my machine booted up, or since chicken have teeth.

I don't get your problem. mdate() uses CLOCK_MONOTONIC (if available), and so 
do vlc_cond_*(). This is required, otherwise vlc_cond_timedwait() could not 
be made to work at all.

-- 
Rémi Denis-Courmont
http://www.remlab.net/



More information about the vlc-devel mailing list