Question

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?

Was it helpful?

Solution

if(!m_cond.timed_wait(lock, boost::posix_time::milliseconds(2000)))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top