std::this_thread::sleep_for
template <class Rep, class Period>
void sleep_for (const chrono::duration<Rep,Period>& rel_time);
Blocks execution of the calling thread during the span of time specified by rel_time.
阻塞当前线程rel_time的时间。
参考链接:http://www.cnblogs.com/jwk000/p/3560086.html一
The execution of the current thread is stopped until at least rel_time has passed from now. Other threads continue their execution.
从当前时间开始阻塞当前线程直到rel_time(一段时间)这段时间过去,其他线程依旧指向。
例子:
// thread::get_id / this_thread::get_id #include <iostream> // std::cout #include <thread> // std::thread, std::thread::id, std::this_thread::get_id #include <chrono> // std::chrono::seconds using namespace std; void show(int n) { if (n==5){ cout<<"start n=5"<<endl; this_thread::sleep_for(chrono::seconds(5)); cout<<"sleep_for(chrono::seconds(5)) end"<<endl; } else{ cout<<"This is not 5"<<endl; } } int main() { thread t(show,5); thread t1(show,100); t.join(); t1.join(); }
运行截图:
Parameters
- rel_time
- The time span after which the calling thread shall resume its execution.
Note that multi-threading management operations may cause certain delays beyond this.
duration is an object that represents a specific relative time.
线程阻塞的时间。
Return value
none
Example
|
|
Output (after 10 seconds):
countdown:
10
9
8
7
6
5
4
3
2
1
Lift off!
|
Exception safety
If the type of rel_time never throws exceptions (like the instantiations of duration in
header <chrono>), this function never throws exceptions (no-throw guarantee).
—————————————————————————————————————————————————————————————————
//写的错误或者不好的地方请多多指导,可以在下面留言或者点击左上方邮件地址给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。
转载请注明出处:http://blog.csdn.net/qq844352155
author:天下无双
Email:coderguang@gmail.com
2014-9-4
于GDUT
——————————————————————————————————————————————————————————————————