简体   繁体   English

在整个系统中使用 std::chrono::steady_clock 时间是否正确?

[英]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.我有一个标头时间作为std::chrono::steady_clock参数的文件。 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我对https://en.cppreference.com/w/cpp/chrono/steady_clock感到困惑

Updates:更新:

Q: Whether the comparison provides me the latest file or not? Q:比较是否给我提供了最新的文件?

Q: Should I use the system_clock instead of steady_clock?问:我应该使用 system_clock 而不是 stable_clock 吗?

Q: Whether the comparison provides me the latest file or not? Q:比较是否给我提供了最新的文件?

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.例如,似乎自进程开始以来可能是时间,并且不同的进程不会就当前的std::chrono::steady_clock时间达成一致。

Retrieved from @François Andrieux's comment might help someone here.从@François Andrieux 的评论中检索可能对这里的人有所帮助。

Q: Should I use the system_clock instead of steady_clock?问:我应该使用 system_clock 而不是 stable_clock 吗?

Answer: When we are working on different servers or systems and trying to compare the std::chrono::steady_clock it will be wrong.答:当我们在不同的服务器或系统上工作并尝试比较std::chrono::steady_clock它会出错。 Use std::chrono::system_clock instead.改用 std::chrono::system_clock 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在C ++实现中std :: chrono :: system_clock vs std :: chrono :: steady_clock的精度是多少? - Precision of std::chrono::system_clock vs std::chrono::steady_clock across C++ implementations? 持久性 std::chrono time_point<steady_clock></steady_clock> - Persistent std::chrono time_point<steady_clock> 不匹配的类型 'std::chrono::_V2::steady_clock' 和 'std::chrono::_V2::system_clock' - mismatched types 'std::chrono::_V2::steady_clock' and 'std::chrono::_V2::system_clock' chrono steady_clock没有给出正确的结果? - chrono steady_clock not giving correct result? 将 std::chrono::steady_clock::time_point 转换为 long double - converting std::chrono::steady_clock::time_point to long double 使用std :: chrono :: steady_clock在线程/异步中对代码进行基准测试 - Using std::chrono::steady_clock to benchmark code in a thread/async std :: chrono :: steady_clock :: now如何报告错误? - How does std::chrono::steady_clock::now report errors? 是否确保 2 个连续的 std::chrono::steady_clock::now() 不相等? - Is it ensured that 2 sequential std::chrono::steady_clock::now() will not be equal? 如何在C ++中为std :: chrono :: steady_clock设置epoch? - How to set epoch for std::chrono::steady_clock in C++? 相当于std :: chrono :: steady_clock :: now();的python - python equivalent of std::chrono::steady_clock::now();
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM