2

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?

Build Succeeded
  • 1,153
  • 1
  • 10
  • 24
  • 1
    What are you confused by exactly? What are the problems you think there could be? – cigien Oct 15 '20 at 16:45
  • 1
    explaination of steady_clock and I doubt that I should use system_clock – Build Succeeded Oct 15 '20 at 16:45
  • 1
    Ok, the dupe should cover that. If you have a more specific question, please edit that in, and explain why the dupe doesn't answer your question. – cigien Oct 15 '20 at 16:47
  • [ref](https://stackoverflow.com/questions/13263277/difference-between-stdsystem-clock-and-stdsteady-clock) – pradeexsu Oct 15 '20 at 16:52
  • 1
    thats fine though that difference question do not answer my particular query – Build Succeeded Oct 15 '20 at 16:53
  • 3
    From the linked page : *"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 `steady_clock` time. – François Andrieux Oct 15 '20 at 16:55
  • @FrançoisAndrieux updated post – Build Succeeded Oct 16 '20 at 13:46
  • @FrançoisAndrieux you are right but the question is closed as a duplicate. So, I dont have that option. I have request to reopen. Lets see – Build Succeeded Oct 16 '20 at 13:52

1 Answers1

2

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.

Build Succeeded
  • 1,153
  • 1
  • 10
  • 24