Boost logo

Boost :

Subject: Re: [boost] [thread] countdown_latch
From: Gaetano Mendola (mendola_at_[hidden])
Date: 2013-05-11 17:25:19

On 27/04/2013 09.05, 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.

Is the explicit lk.unlock() inside the

bool count_down(unique_lock<mutex> &lk);

needed ?

I see the two places where it's called are:

void count_down()
   boost::unique_lock<boost::mutex> lk(mutex_);


void count_down_and_wait()
   boost::unique_lock<boost::mutex> lk(mutex_);
   if (count_down(lk))
   count_.cond_.wait(lk, detail::counter_is_zero(count_));

in both cases the unique_lock does the job, or I'm missing

Also I would add a new method to boost::detail::counter

   bool dec_and_notify_all_if_value(const std::size a_value)
     if (--value_ == a_value)
       return true;
     return false;

This way you can further simplify the count_down(unique_lock<mutex> &lk)

     //lk is here only to assure it's a thread safe call
     bool count_down(unique_lock<mutex> &lk)
     /// pre_condition (count_.value_ > 0)
       BOOST_ASSERT(count_.value_ > 0);
       return count_.dec_and_notify_all_if_value(0);

Gaetano Mendola

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