4 ms·
Why doesn't the OS take care of this? It seems like the prototypical task for the OS.
by amelius 11y ago
Why doesn't the OS take care of this?
It seems like the prototypical task for the OS.
- lostcolony 11y agoBecause Erlang runs in a VM, and that VM provides certain useful guarantees that may or may not be provided by the underlying OS. Per the original announcement about the r18 release - If time correction is enabled, the Erlang runtime system will make use of both OS system time and OS monotonic time, in order to make adjustments of the frequency of the Erlang monotonic clock. You can check if your system has support for OS monotonic time by calling erlang:system_info(os_monotonic_time_source), and you can check if time correction is enabled on your system by calling erlang:system_info(time_correction). But that's not always enough, it isn't always available, and it's not always what you want, either. Per the end of the OP (and also the official release) - To find system time: erlang:system_time/0-1 To measure time differences: call erlang:monotonic_time/0-1 twice and subtract them To define an absolute order between events on a node: erlang:unique_integer([monotonic]) Measure time and make sure an absolute order is defined: {erlang:monotonic_time(), erlang:unique_integer([monotonic])} Create a unique name: erlang:unique_integer([positive]). Couple it with a node name if you want the value to be unique in a cluster, or try using UUIDv1
- scott_karana 11y agoI agree. System clocks should be based off of "International Atomic Time", TAI, which is also monotonic, and not subject to UTC's leap seconds, as UTC is calculated as an offset of TAI.
- rvirding 11y agoYes, but the VM clock guaranteed more, every time you access the clock using erlang:now() you would get a monotonically increasing value. Practical to be sure, but not scalable.
- scott_karana 11y agoHow does TAI not also solve monotonically increasing values, and in a standardized way to boot? That's a characteristic of it by definition, as I tried to explain. :P