|
Boost Users : |
Subject: Re: [Boost-users] condition variable predicate and lambda
From: Igor R (boost.lists_at_[hidden])
Date: 2011-10-18 16:08:44
> All I want to do is wait for a specified amount of time for a member variable
> of my class to equal a certain value.
>
> Can someone please help me with an example?
>
> I've tried several that came from Googling and read the documentation, but I
> get compile errors no matter what I try.
>
> Currently the compiler is complainging "term does not evaluate to a function
> taking 0 arguments"
>
> Here is the problem in all its simplicity:
>
> class A
> {
> public:
>
> Â enum STATE
> Â {
> Â Â Â HAPPY = 0,
> Â Â Â SAD,
> Â Â Â ANGRY,
> Â Â Â NUM_STATES
> Â };
>
> Â Foo(boost::posix_time::millisec & timeout)
> Â {
> Â Â Â // I need to wait to return from this until the state is HAPPY
>
> Â }
>
> private:
> Â STATE state_;
> };
{
unique_lock lock(mutex_);
condvar_->timed_wait(lock, timeout, lambda::var(state_) == HAPPY);
}
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