Hacker News new | past | comments | ask | show | jobs | submit login

This is why clock_gettime() allows you to specify which clock to use. According to POSIX, CLOCK_MONOTONIC is not supposed to have any sudden jumps due to time adjustments or leap seconds, but can be adjusted for the gradual drift the clock experiences with respect to real world time. It seems perfect for your use case (if you don't want the skew adjustment there's also CLOCK_MONOTONIC_RAW, but since there is no skew adjustment it's only reasonably accurate for events that are close together).



CLOCK_MONOTONIC is good, but it's a local clock without a defined reference. So you can't use it on the network to synchronize different computers or otherwise communicate absolute timestamps. There should be a CLOCK_REALTIME_RAW or something that gives you the TAI time (UTC without correction for leap seconds).


Ah, I see what you mean. A standard API for synchronising non-local events would definitely make life easier.


Linux has CLOCK_TAI.


That's great to know. I had no idea since it's not mentioned in the man page for clock_gettime (part of the "Linux Programmer's Manual"). Apparently the man pages are out of date.




Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: