开发者

sleep for many days with resolution of microseconds

Is there a way to pu开发者_如何学JAVAt a thread to sleep for many days with a resolution of microseconds? usleep can only put the thread to sleep for 1000000 and sleep works in second steps. Is there a way to, may be, use both sleep and usleep to achieve this?


While it is not yet time to wake up:

  • Check the current time
  • Go to sleep a bit shorter than when you want to wake up.

This way, you can periodically check the time, increasingly faster and more detailed as you reach the time you want to wake up.


Just divide the large sleep in several small sleep periods.

int64_t time_to_sleep = ...;
int peroid_to_sleep = ...;
while( time_to_sleep > 0 )
{
     usleep( period_slept );
     time_to_sleep -= period_slept; 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜