Skip to main content

Module sync

Module sync 

Source
Expand description

Poison-tolerant locking for std::sync::Mutex.

std::sync::Mutex poisoning is advisory bookkeeping: a guard dropped while panicking flags the mutex, but the guarded value is often still consistent. Panicking on every subsequent lock() turns one localized failure into a process-wide cascade, especially for process-global state and cleanup paths.

VT Code’s policy:

  • short synchronous critical sections use parking_lot::Mutex (no poison);
  • where std::sync::Mutex is required, use lock_or_recover so poison is recovered instead of propagated;
  • callers with a genuine mid-critical-section invariant should model poison explicitly rather than relying on the standard library’s boolean flag.

Functions§

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