I would like to wait for a condition for a certain amount of time.
I read the boost documentation and it seems that it is preferable to use the function wait_for
with a predicate, as described here.
Unfortunately the example is not really useful for me. How should I write the predicate? I tried to write the code reported above but the visual studio compiler is complaining: c:\boost\boost\thread\win32\condition_variable.hpp(394): error C2064: term does not evaluate to a function taking 0 arguments
This is the part of the code:
class MyClass{
boost::mutex mutex;
boost::condition_variable myCondition;
//...
void foo();
bool myPredicate();
}
void MyClass::foo(){
boost::unique_lock<boost::mutex> lock(mutex);
boost::chrono::microseconds period(25000);
// ...
boost::chrono::system_clock::time_point wakeUpTime = boost::chrono::system_clock::now() + period;
if(myCondition.wait_until(lock,wakeUpTime,MyClass::myPredicate) == true){/...}
}
bool MyClass::myPredicate(){
if(...)
return true;
else
return true;
}
What's the correct way of using wait_for
with predicate?