View Single Post
danramos's Avatar
Posts: 4,672 | Thanked: 5,455 times | Joined on Jul 2008 @ Springfield, MA, USA
#102
Originally Posted by daperl View Post
Syncing in user space should be simple. The following psuedo code would cost very little and makes the reasonable assumption that sleeping will take no less than 60 seconds and no more than a 120 seconds.

Code:
def clock_update():
  while not_done:
    now = get_system_time_in_seconds()
    update_clock (now)
    sleep_time = 60 - now MOD 60
    sleep_for_seconds (sleep_time)

clock_update_thread = threading.Thread (target=clock_update)
clock_update_thread.start()
Oooo.. true.. true. This would still use sleep, free up CPU cycles AND consistently keep the clock very reasonably accurate. This goes around the whole need for dillying with interrupts.

Simple and effective. I love it.
 

The Following User Says Thank You to danramos For This Useful Post: