boost库中sleep方法详解

博客转载自:https://blog.csdn.net/huang_xw/article/details/8453506

boost库中sleep有两个方法:

1. 这个方法只能在线程中用, 在主线程中用无效

void sleep(TimeDuration const& rel_time);  
void sleep(system_time const& abs_time);  

实例:

boost::this_thread::sleep(boost::posix_time::seconds(2));    // 这种更好用  
boost::this_thread::sleep(boost::get_system_time() + boost::posix_time::seconds(2));  

2. 在主线程中使用

原型:

sleep(const system_time& xt);  

实例:

boost::thread::sleep(boost::get_system_time() + boost::posix_time::seconds(5));  

  

猜你喜欢

转载自www.cnblogs.com/flyinggod/p/9131631.html