It gets especially interesting when you start thinking about mutexes and condition variables with timeouts.
It gets especially interesting when you start thinking about mutexes and condition variables with timeouts.
But I notice that your solution is POSIX only. How about Windows?
And how do NTP adjustments affect this solution -- surely when the NTP server tells you your system clock is consistently off by 16%, there's got to be some effect on clock_gettime with CLOCK_MONOTONIC, right? I'd like to retain the ability to use NTP to improve the accuracy of the results.
UNIX time is not actually seconds since the epoch. It's just something very, very close. There are a few cases where the same time_t value repeats for two seconds in order to insert a leap second.
With regard to Windows, I assume there are equivalents to all these interfaces, but I don't know what they are.