In the documentation for std::condition_variable, there is an overload of wait() taking as argument a predicate function. The function will wait until the first wake_up at which the predicate function is true.
In the documentation
It is stated that this is equivalent to:
while (!pred()) {
wait(lock);
}
But also:
This overload may be used to ignore spurious awakenings while waiting for a specific condition to become true. Note that before enter to this method lock must be acquired, after wait(lock) exits it is also reacquired, i.e. lock can be used as a guard to pred() access.
I'm not sure to understand, are these strictrly equivalent (in which case I prefer the plain while loop which is easier to read than the overload with a lambda in my case), or is the overload (possibly implementation depending) more efficient?
Could an implementation evaluate the predicate in the notifying thread before awakening the waiting thread, in order to avoid awakening when the test condition is false? c++ thread guru needed here...
Thanks