0
votes

Usage of Condvar in Rust is something like this:

let pair = Arc::new((Mutex::new(true), Condvar::new()));
//...
let (lock, cvar) = &*pair;
let _guard = cvar.wait_while(lock.lock().unwrap(), SOMETHING_HERE).unwrap();

Is there something that I can put in SOMETHING_HERE that waits in the right way? I'm thinking about the simplest way of solving this.

My idea is to have a third condition variable that waits for two variables related to the other conditions, but I don't know how to do this.

1

1 Answers

2
votes

Create a third Condvar and remember to notify it each time you notify either of the first two.

Consider using one Condvar anyway. Since they can wake up spuriously, you already need to check the “predicate”, i.e. whether there have actually been any relevant changes to the Mutex.