boost库中sleep方法详解

来源:互联网 发布:mac系统使用教程视频 编辑:程序博客网 时间:2024/06/05 23:03
boost库中sleep有两个方法:
1. 这个方法只能在线程中用, 在主线程中用无效. 
原型:

[cpp] view plaincopyprint?
  1. void sleep(TimeDuration const& rel_time);  
  2. void sleep(system_time const& abs_time);  
实例:
[cpp] view plaincopyprint?
  1. boost::this_thread::sleep(boost::posix_time::seconds(2));    // 这种更好用  
  2. boost::this_thread::sleep(boost::get_system_time() + boost::posix_time::seconds(2));  
2. 在主线程中使用
原型:

[cpp] view plaincopyprint?
  1. sleep(const system_time& xt);  
实例:
[cpp] view plaincopyprint?
  1. boost::thread::sleep(boost::get_system_time() + boost::posix_time::seconds(5));  

原创粉丝点击