How to stop time from running backwards on Linux?

后端 未结 5 1114
情书的邮戳
情书的邮戳 2021-02-12 11:15

Here\'s a little test I\'ve written to verify that time does indeed only run forwards in Linux.

#include 
#include   

bool timeG         


        
5条回答
  •  执念已碎
    2021-02-12 11:49

    Time should not run backwards on real hardware; on a VM your mileage may vary.

    In any case, your application should probably not assume that time doesn't run backwards by a very small amount (think, maybe 1 second).

    Yes, clock_gettime is good but even that could run backwards in the case of faulty hardware (or a VM, as in your example).

    I have seen a hardware bug make time run backwards (albeit very occasionally), it was a cause of some very peculiar problems.

    In particular, anything which involves comparing file timestamps will go wrong when time goes backwards.

提交回复
热议问题