Boost logo

Boost Users :

Subject: Re: [Boost-users] [chrono][thread] Best way to wait?
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2013-03-29 11:37:43


AMDG

On 03/29/2013 08:23 AM, Klaim - Joël Lamotte wrote:
> Hi,
> can someone clarify:
> 1. what is the difference between:
>
> const auto wait_time = boost::chrono::miliseconds( 8 );
> boost::mutex mutex;
> boost::unique_lock<boost::mutex> lock( mutex );
> boost::condition_variable wait_condition;
> wait_condition.wait_for( lock, wait_time );
>
> and
>
> const auto wait_time = boost::chrono::miliseconds( 8 );
> boost::this_thread::sleep_for( wait_time );
>

A thread waiting on a condition variable (a) can
be explicitly notified and (b) may wake up before
the time has expired (spurious wakeups). If you
just want to sleep for a fixed amount of time, then
sleep_for is the right tool.

> 2. are there other ways to wait? (I mean make the thread sleep, not looping
> until it's time)
>

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net