Skip to content

Comment on The Colour Clockparent

Comments

On POSIX systems, clock_nanosleep() can accept an absolute time argument.

  // In a real program one would probably not use time()
  // Also, some older pre-release versions of the realtime
  // kernel patches had the clock_nanosleep() and time() 
  // clocks out of sync by 0.5s (IIRC)
  for(;;) {
    struct timespec after_epoch = { .tv_sec = time(NULL) + 1, .tv_nsec = 0 };
    // Check for EINTR in a real program
    clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &after_epoch, NULL);
    printf("Tick\n");
  }
http://pubs.opengroup.org/onlinepubs/009695399/functions/clo...

Unfortunately, this probably doesn't help with Flash or JavaScript clock demos.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.