Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost::condition_variable_any] Telling cond to unlock_share()
From: Howard Hinnant (howard.hinnant_at_[hidden])
Date: 2011-03-28 19:26:34


On Mar 28, 2011, at 6:34 PM, Panagiotis Foteinos wrote:

> Thank you for the reply.
>
> To clarify things in my mind:
> Should I pass the lock itself to cond.wait for safety/correctness, or because this way I will get the desired behavior?

To have cond.wait call unlock_shared() / lock_shared(), cond should be of type condition_variable_any, and you should pass in shared_lock<shared_mutex> with owns_lock() == true.

If you pass a shared_mutex directly to condition_variable_any::wait(), it will call unlock() on the mutex, which will be a run time error if the mutex has been lock_shared().

If you pass a shared_mutex or shared_lock to a condition_variable::wait() (as opposed to condition_variable_any), you will get a compile time error.

-Howard


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