Synchronising an app with the system clock



Hi list

I wrote	a quick app to alert me every time the clock strikes the hour.
Unfortunately, I found no better way to do this than to check, every
second, to see if the current local time's minutes and seconds are 0.

This involves a glib timeout of 1000ms, which I understand is not 100%
guaranteed to work because it might skip from, e.g. 15:59:59.999 to
16:00:01.000 if I am unlucky and it actually takes 1001ms to fire. You
might think to increase the resolution to 500ms, but then I need to keep
track of state to make sure I don't fire the alarm twice. This quickly
gets out of hand.

I initially thought of just checking the current time, and then
calculating how long until the hour, and sleeping until then. There is a
problem with this, however, in that if the time changes, the alarm will
go off at the wrong time as it has no knowledge of the clock change.

What I want to do is have some way of absolutely synchronising an app
with the system clock. I've considered a kind of D-Bus system clock
service that could emit signals every second so that apps could
synchronise to that and all dance in time, but that itself would need
synchronising somehow, so the problem remains. Is there some way to
interface with the kernel for this kind of thing?

Any other ideas/comments?

Cheers
-- 
Alex Jones
http://alex.weej.com/




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]