AKIWEB
AKIWEB

Reputation: 19612

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?

Upvotes: 0

Views: 163

Answers (1)

Benjamin Lindley
Benjamin Lindley

Reputation: 103693

if(!m_cond.timed_wait(lock, boost::posix_time::milliseconds(2000)))

Upvotes: 4

Related Questions