当前位置: 动力学知识库 > 问答 > 编程问答 >

multithreading - sleep the thread using milliseconds instead of using seconds in C++

问题描述:

I have a boost condition variable which I am using to sleep a thread.

 boost::condition_variable m_cond;

Currently I am using like this in which I am passing the lock and the seconds to which it has to sleep. Currently it will sleep for 10 seconds

if(!m_cond.timed_wait(lock, boost::posix_time::seconds(10))){

}

Is there any way to do same thing in milliseconds? Instead of passing that as a seconds, can I pass the number of milliseconds it has to wait? Suppose if I need to wait for 2 seconds, then I would like to pass 2000 ms as the value. This doesn't work -

long ms = 2000;

if(!m_cond.timed_wait(lock, ms)){

}

Is there any other way of doing it?

网友答案:
if(!m_cond.timed_wait(lock, boost::posix_time::milliseconds(2000)))
分享给朋友:
您可能感兴趣的文章:
随机阅读: