[boost-thread] error in the docs???
Hello *, I think there is an error in the docs at: http://www.boost.org/doc/libs/1_38_0/doc/html/thread/synchronization.html#th... Member Function of condition_variable class is documented as: template<typename predicate_type> void wait(boost::unique_lockboost::mutex& lock, predicate_type pred) Effects: As-if while(!pred()) { wait(lock); } Should be: template<typename predicate_type> void wait(boost::unique_lockboost::mutex& lock, predicate_type pred) Effects: As-if while(pred()) //!!!!! no not operator { wait(lock); } If I pass the negated predicate to the wait, my thread blocks forever, whereas passing the predicate works as intended. This applies to the version 1.36, but 1.38 states the same in the docs. Thanks, Ovanes
AMDG Ovanes Markarian wrote:
I think there is an error in the docs at: http://www.boost.org/doc/libs/1_38_0/doc/html/thread/synchronization.html#th...
Member Function of condition_variable class is documented as:
template<typename predicate_type> void wait(boost::unique_lockboost::mutex& lock, predicate_type pred)
Effects:
As-if
while(!pred()) { wait(lock); }
Should be:
template<typename predicate_type> void wait(boost::unique_lockboost::mutex& lock, predicate_type pred)
Effects:
As-if
while(pred()) //!!!!! no not operator { wait(lock); }
If I pass the negated predicate to the wait, my thread blocks forever, whereas passing the predicate works as intended. This applies to the version 1.36, but 1.38 states the same in the docs.
wait returns when the predicate is true, so the docs are correct. In Christ, Steven Watanabe
Steven, hi!
thanks for the answer!
On Thu, Mar 19, 2009 at 12:13 AM, Steven Watanabe
AMDG
wait returns when the predicate is true, so the docs are correct.
In Christ, Steven Watanabe
Did you test it? In my case wait returns when the predicate is false. I use an empty circular buffer and call from the same thread this code: using namespace boost; scoped_lock lock(mutex_); wait_for_free_slots_.wait(lock, bind(&buffer_type::full, buffer_)); //wait_for_free_slots_ is a condition variable buffer_.push_back(item); wait_for_items_.notify_all(); This line returns immediately wait_for_free_slots_.wait(lock, bind(&buffer_type::full, buffer_)); //wait_for_free_slots_ is a condition variable If you inverse the predicate it blocks forever. Thanks, Ovanes
AMDG Ovanes Markarian wrote:
Did you test it? In my case wait returns when the predicate is false. I use an empty circular buffer and call from the same thread this code:
using namespace boost;
scoped_lock lock(mutex_); wait_for_free_slots_.wait(lock, bind(&buffer_type::full, buffer_)); //wait_for_free_slots_ is a condition variable
buffer_.push_back(item); wait_for_items_.notify_all();
This line returns immediately wait_for_free_slots_.wait(lock, bind(&buffer_type::full, buffer_)); //wait_for_free_slots_ is a condition variable
If you inverse the predicate it blocks forever.
Seems to work for me
#include
participants (2)
-
Ovanes Markarian
-
Steven Watanabe