1. 程式人生 > >boost庫中sleep方法詳解

boost庫中sleep方法詳解

seconds boost庫 color sys 在線 TP 方法 轉載 details

博客轉載自: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));  

  

boost庫中sleep方法詳解