Is the epoch of steady_clock relative to when the operating system starts? or to the process itself?

99封情书 提交于 2021-02-05 06:01:41

问题


Using boost::chrono::steady_clock or std::chrono::steady_clock is suppose to guarantee that physical time is always monotonic and is not affected by date time changes in the system. Here is my question, if I have two processes that need to be immune to system date time changes, is it enough to exchange just the time_since_epoch? In other words, the time interpretation of the two processes to the same time since epoch will be the same? Specifically I need to answer this question for Windows and QNX.

EDIT: Both processes are running in the same computer, same operating system and communicate via IPC calls.


回答1:


No the times are not interchangeable between systems, because C++ doesn't specify the epoch. The epoch is depending on the operating system, different systems can have different epochs.

If, on the other hand, you share the times only locally, within the same system, then it's okay.




回答2:


C++ standard says about steady_clock:

20.12.7.2 Class steady_clock [time.clock.steady]

Objects of class steady_clock represent clocks for which values of time_point never decrease as physical time advances and for which values of time_point advance at a steady rate relative to real time. That is, the clock may not be adjusted.

Compare this to what the standard has to say about system_clock:

20.12.7.1 Class system_clock [time.clock.system]

Objects of class system_clock represent wall clock time from the system-wide realtime clock.

There's no mention about steady_clock being "system-wide", which leads me to believe that, according to the C++ standard, you cannot trust on two steady_clocks in different processes on the same machine having the same epoch.



来源:https://stackoverflow.com/questions/30882953/is-the-epoch-of-steady-clock-relative-to-when-the-operating-system-starts-or-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!