Matthew Garrett ([personal profile] mjg59) wrote,
@ 2011-11-17 08:39 am UTC
  • Previous Entry
  • Add to Memories
  • Tell someone about this!
  • Next Entry
Entry tags:advogato, fedora
A reasonably common design for applications that want to run code at a specific time is something like:

time_t wakeup_time = get_next_event_time();
time_t now = time(NULL);
sleep(wakeup_time-now);

This works absolutely fine, except that sleep() ignores time spent with a suspended system. If you sleep(3600) and then immediately suspend for 45 minutes you'll wake up after 105 minutes, not 60. Which probably isn't what you want. If you want a timer that'll expire at a specific time (or immediately after resume if that time passed during suspend), use the POSIX timer family (timer_create, timer_settime and friends) with CLOCK_REALTIME. It's a signal-driven interface rather than a blocking one, so implementation may be a little more complicated, but it has the advantage of actually working.


(Read 19 comments) - (Post a new comment)
(Flat) (Top-level comments only)


[personal profile] mjg59
2011-11-17 06:55 pm UTC (link)
What's the argument that it should be? It's a spec. You're supposed to have clearly defined terms. We can argue that Linux's current behaviour is in violation, but we can't clearly demonstrate that.

(Reply to this)  (Thread from start)  (Parent



(Read 19 comments) - (Post a new comment)
(Flat) (Top-level comments only)