I created this function. It should wait to finish before running again. This is working. I used the Condvar docs to write this code, but I don’t quite understand why the lock isn’t blocking.
When executing the run first the lock is locked and only unlocked when the task is done. When I call run while it is already running why can I lock the Mutex again.
pub fn run(&self) {
let (lock, cvar) = &self.running;
let mut running = lock.lock().unwrap();
while *running {
running = cvar.wait(running).unwrap();
}
*running = true;
// Logic that can only run once at the same time
...
*running = false;
cvar.notify_all();
}
New contributor
user25233820 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.