linux如何停止时间校准,c++ 如何在Linux上停止时间倒退?

这是一个我写的验证时间确实只在Linux中前进的一点测试。

#include

#include

bool timeGoesForwardTest2()

{

timeval tv1, tv2;

double startTime = getTimeSeconds(); // my function

while ( getTimeSeconds() - startTime < 5 )

{

gettimeofday( &tv1, NULL );

gettimeofday( &tv2, NULL );

if ( tv2.tv_usec == tv1.tv_usec &&

tv2.tv_sec == tv1.tv_sec )

{

continue; // Equal times are allowed.

}

// tv2 should be greater than tv1

if ( !( tv2.tv_usec>tv1.tv_usec ||

tv2.tv_sec-1 == tv1.tv_sec ) )

{

printf( "tv1: %d %d\n", int( tv1.tv_sec ), int( tv1.tv_usec ) );

printf( "tv2: %d %d\n", int( tv2.tv_sec ), int( tv2.tv_usec ) );

return false;

}

}

return true;

}

测试失败,结果。

tv1: 1296011067 632550

tv2: 1296011067 632549

嗯…

为什么会发生这种情况?

这是我的设置:

Linux version 2.6.35-22-generic (buildd@rothera) (gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu4) ) #33-Ubuntu SMP Sun Sep 19 20:34:50 UTC 2010 (Ubuntu 2.6.35-22.33-generic 2.6.35.4)

... running inside VirtualBox 3.2.12, in Windows 7.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值