[boost::condition_variable_any] Telling cond to unlock_share()

Hello users. Documentation says that cond.wait(mtx) blocks the current thread and invokes mtx.unlock(). What if I want cond.wait(mtx) to call mtx.unlock_shared() instead? Is there any way to do so? Regards, Panagiotis Foteinos

AMDG On 03/28/2011 03:03 PM, Panagiotis Foteinos wrote:
Hello users.
Documentation says that cond.wait(mtx) blocks the current thread and invokes mtx.unlock().
What if I want cond.wait(mtx) to call mtx.unlock_shared() instead? Is there any way to do so?
You should pass the unique_lock or shared_lock to cond.wait, instead of passing the mutex itself. In Christ, Steven Watanabe

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?
Best Regards,
Panagiotis Foteinos
On Mon, Mar 28, 2011 at 6:20 PM, Steven Watanabe
AMDG
On 03/28/2011 03:03 PM, Panagiotis Foteinos wrote:
Hello users.
Documentation says that cond.wait(mtx) blocks the current thread and invokes mtx.unlock().
What if I want cond.wait(mtx) to call mtx.unlock_shared() instead? Is there any way to do so?
You should pass the unique_lock or shared_lock to cond.wait, instead of passing the mutex itself.
In Christ, Steven Watanabe _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

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
participants (3)
-
Howard Hinnant
-
Panagiotis Foteinos
-
Steven Watanabe