C++11this_threadsleep_for(10)
原文地址:http://www.cplusplus.com/reference/thread/this\_thread/sleep\_for/
function
std::this_thread::sleep_for
template <class Rep, class Period>
void sleep_for (const chrono::duration<Rep,Period>& rel_time);
Sleep for time span
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
#include
#include
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
1 | 1 |
1 | // this_thread::sleep_for 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
—————————————————————————————————————————————————————————————————
//写的错误或者不好的地方请多多指导,可以在下面留言或者点击左上方邮件地址给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。
转载请注明出处:http://blog.csdn.net/qq844352155
author:天下无双
Email:coderguang@gmail.com
2014-9-4
于GDUT
——————————————————————————————————————————————————————————————————
- 本文作者: royalchen
- 本文链接: http://www.royalchen.com/2016/02/24/c11this-threadsleep-for10/
- 版权声明: 本博客所有文章除特别声明外,均采用 MIT 许可协议。转载请注明出处!