2011-02-25 18 views
0

所以我创建了一些代码。我使用升压计时器。这里是可以提升boost :: posix_time :: milliseconds将接近0的值变成0?

 while(1){ 
     timerForCaptureFame.restart(); 
    //some code 
     spendedTimeForCaptureFame = timerForCaptureFame.elapsed(); 
     if(spendedTimeForCaptureFame < desiredTimeForCaptureFame){ 
       boost::this_thread::sleep(boost::posix_time::milliseconds(desiredTimeForCaptureFame - spendedTimeForCaptureFame)); 
     } 
} 

可以在发生,使desiredTimeForCaptureFame - spendedTimeForCaptureFame会> 0,但升压会把它为0,只是暂停线程?

+0

nope - 在此线程启动之前设置所需的时间。 – Rella 2011-02-25 19:11:47

+0

我的意思是问题是 - 线程工作了一段时间比跌倒睡觉... – Rella 2011-02-25 19:13:33

+0

删除了我原来的评论,因为它看起来像你使用boost :: timer,所以你正在处理双打。 – 2011-02-25 19:27:55

回答

2

boost::this_thread::sleep(0)不应该“暂停线程”;它应该立即返回。已经发布了关于boost::this_thread::sleep挂起的bug报告,所以可能是你已经打到了这个bug ---如果是这样,我会感谢更多的细节,因为我自己无法再现它。

相关问题