Folks, in my application I'm using clock_gettime(CLOCK_MONOTONIC)
in order to measure the delta time between frames (a typical approach in gamedev) and from time to time I'm facing a strange behavior of clock_gettime(..)
- returned values occasionally are not monotonic (i.e prev. time is bigger than current time).
Currently, if such a paradox happens I simply skip the current frame and start processing the next one.
The question is how can this be possible at all? Is it a bug in Linux POSIX implementation of clock_gettime
? I'm using Ubuntu Server Edition 10.04 (kernel 2.6.32-24, x86_64), gcc-4.4.3.
man clock_gettime
says:Since
CLOCK_MONOTONIC_RAW
is not subject of NTP adjustments, I guessCLOCK_MONOTONIC
could be.We had similar problems with Redhat Enterprise 5.0 with 2.6.18 kernel and some specific Itanium processor. We couldn't reproduce it with other processor on the same OS. It was fixed in RHEL 5.3 with slightly newer kernel and some Redhat patches.
Sure sounds like a bug to me. Perhaps you should report it in Ubuntu's bug tracker.
Looks like an instance of
See here for a patch. This was included into 2.6.32.19, but may not have been backported by the Debian team(?). You should check it out.
It's a linux bug. No ajustment in a monotonic clock can make it go backwards. You're using a very old kernel and a very old distribution.
Edit: are you sure you need to skip the frame ? If you call clock_gettime again, what happens ?
Try
CLOCK_MONOTONIC_RAW
.