Skip to main content

lock_or_recover

Function lock_or_recover 

Source
pub fn lock_or_recover<T>(mutex: &Mutex<T>) -> MutexGuard<'_, T>
Expand description

Lock mutex, returning the guard even if a previous holder panicked.

Accepts &Mutex<T> and, through deref coercion, &Arc<Mutex<T>>. On stable Rust this is the non-panicking alternative to mutex.lock().unwrap(); panic-freedom matters most in globals, shutdown, and panic-hook paths where a second panic aborts the process.