On Tue, Apr 10, 2012 at 1:03 AM, William Ahern <will...@25thandclement.com> wrote: > On Tue, Apr 10, 2012 at 11:44:39AM +0800, 卓宜黄 wrote: >> Hi all, >> >> I found an issue that it will trigger the timer callback dramatically >> like a dead looping when moving the system time backward for a year >> and then moving it forward to the accurate time. > > AFAICT, the libevent 2.x code uses clock_gettime(CLOCK_MONOTONIC) if > available. > > Does your system provide CLOCK_MONOTONIC? Most do (including the ones I use > the most, Linux and OpenBSD).
I think he's on Windows. With Windows, your options for monotonic timekeeping seem to be QueryPerformanceCounter, and GetTickCount. Neither one is really great from what I can tell: QueryPerformanceCounter is slow and has known bugs on some older windows versions and some VMs, whereas GetTickCount only has a 1 ms resolution and 15 ms accuracy by default. > One notable exception is OS X. But OS X _does_ > provide a monotonic counter. If you're using OS X, try this compat wrapper: I actually added support for the OSX monotonic counter to 2.1.x just yesterday in commit b8fd6f918b4540. If somebody who knows the mach/osx stuff a bit better than I do wants to check it out, that would be great. I found PEP ( 418 http://www.python.org/dev/peps/pep-0418 ) to be a pretty useful summary of cross-platform monotonic clocks, such as they are. One remaining issue with monotonic clocks is that they don't all behave the same when the system sleeps and resumes. Some of them act as if the missing time never happened (which is probably more like what Libevent needs), but others treat the clock as having jumped forward, which could cause the same undesirable behavior that the original poster is seeing with periodic timer events. yrs, -- Nick *********************************************************************** To unsubscribe, send an e-mail to majord...@freehaven.net with unsubscribe libevent-users in the body.