Boost logo

Boost :

Subject: Re: [boost] [thread] countdown_latch
From: Michael Marcin (mike.marcin_at_[hidden])
Date: 2013-04-27 03:51:26

On 4/27/2013 2:05 AM, Vicente J. Botet Escriba wrote:
> The change set is To
> see the sources, you would need to update the trunk or to take a look at
> Please let me know what do you think.

I think in latch your wait_for and wait_until don't work correctly in
the case of spurious wakes.

The easy answer to this is probably use the predicate versions, which
will also handle the technicalities of turning wait_for into wait_until
during loops caused by spurious wakes.


struct count_not_zero
     count_not_zero(const std::size_t& count_) : count(count_) {}
     bool operator()() const { return count != 0; }
     const std::size_t& count;

template <class Rep, class Period>
cv_status wait_for(const chrono::duration<Rep, Period>& rel_time)
     boost::unique_lock<boost::mutex> lk(mutex_);
     return cond_.wait_for(rel_time, count_not_zero(count_));

template <class lock_type, class Clock, class Duration>
cv_status wait_until(const chrono::time_point<Clock, Duration>& abs_time)
     boost::unique_lock<boost::mutex> lk(mutex_);
     return cond_.wait_until(abs_time, count_not_zero(count_));

You should probably also add a latch_any to go along with

Boost list run by bdawes at, gregod at, cpdaniel at, john at