ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.7k stars 2.53k forks source link

OS clocks may not be monotonically increasing. #6111

Open yurapyon opened 4 years ago

yurapyon commented 4 years ago

Hi! Looking at the Rust source for Instant::now() link, it seems that on some operating systems and hardware, the system clock may not be guaranteed to be monotonically increasing.

I noticed Zig's Timer doesn't account for this. Rust goes for a global mutex as the answer, but this seems more fitting for an atomic?

msingle commented 4 years ago

Having a good way of dealing with monotonic time early on would be very good. Erlang docs on time with more explanation shows some of the complexity. This can also help avoid making api/design decisions which upset people later (eg. this Go discussion )