Search code examples
c++c++11c++-chrono

Is it correct to use std::chrono::steady_clock time across the system?


I have a file with header time as std::chrono::steady_clock parameter. The different server will be writing them on the disk. During the usage of file, I will be comparing them to find the latest time. I am confused with https://en.cppreference.com/w/cpp/chrono/steady_clock

Updates:

Q: Whether the comparison provides me the latest file or not?

Q: Should I use the system_clock instead of steady_clock?


Solution

  • Q: Whether the comparison provides me the latest file or not?

    Answer: With reference to link shared above:

    "This clock is not related to wall clock time (for example, it can be time since last reboot), and is most suitable for measuring intervals."

    It does not seem appropriate for time stamping in a file. For example it seems like it could be time since the process started, and different processes would not agree on the current std::chrono::steady_clock time.

    Retrieved from @François Andrieux's comment might help someone here.

    Q: Should I use the system_clock instead of steady_clock?

    Answer: When we are working on different servers or systems and trying to compare the std::chrono::steady_clock it will be wrong. Use std::chrono::system_clock instead.