boost.thread时间的设置

来源:互联网 发布:java精彩编程200例 编辑:程序博客网 时间:2024/05/16 01:33

boost.thread时间一般有两种指定方式:

1. 指定超时的时间点

boost::xtime xt;
boost::xtime_get(&xt, boost::TIME_UTC);    // initialize xt with current time
xt.nsec += 1000*1000*10;    // change xt to next second
 boost::thread::sleep(xt);    // 休眠10毫秒

 

 boost::thread::sleep(boost::get_system_time()+boost::posix_time::milliseconds(20)); //休眠20毫秒

 

2.指定从当前时间起多久时间之后超时

boost::posix_time::milliseconds tt(10);  // 10毫秒

thread.timed_join(tt); //  10毫秒后超时

 

 

boost.thread内凡是指定时间的地方,一般都是这两种方法.