Skip to content

Commit

Permalink
on Linux, use CLOCK_MONOTONIC for clock_gettime()
Browse files Browse the repository at this point in the history
On Linux systems which are being driven by an external time source (NTP or PTP), it is possible that time appears to slew in reverse under `CLOCK_REALTIME`. Since the timer function is used to time durations of events (calls to `select()`), it is better to use `CLOCK_MONOTONIC`, which isn't subject to slewing.
  • Loading branch information
pao committed Nov 10, 2015
1 parent ef7f77d commit 98f1c31
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/impl/unix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ MillisecondTimer::timespec_now ()
time.tv_sec = mts.tv_sec;
time.tv_nsec = mts.tv_nsec;
# else
clock_gettime(CLOCK_REALTIME, &time);
clock_gettime(CLOCK_MONOTONIC, &time);
# endif
return time;
}
Expand Down

0 comments on commit 98f1c31

Please sign in to comment.