Boost logo

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