Expand description
Lock helpers that ignore poisoning, so one panic cannot fail every later caller. Poison-proof lock helpers, and the rules the locks are taken by.
A lock’s contents are only ever plain data here - a flag, a status, a
message - so a panic while it was held leaves nothing inconsistent behind.
Reading through these helpers instead of expecting keeps one panic from
turning a lock into a permanent failure for every later caller. That
premise holds only while a lock covers data and nothing else, which is
what the rules below are for:
- A guard covers a critical section and no user code. A callback, a query into a world, anything that may panic, runs before the lock is taken or after it is dropped. Reading a batch out under its lock and running the caller’s closure without it is the shape to copy.
DebugandDisplaynever wait on a lock. A value is printed from a panic handler, a log line or a signal handler, sometimes while another lock is held, so these implementations print the shape of the value instead of reading it, and a derived one prints what the standard library’s ownMutexandRwLockimpls offer - which is a try, not a wait.- No lock is taken while another is held, so there is no order to keep and no way for two of them to wait on each other. A place that needs two takes the first, copies what it needs out of it, and drops it before taking the second.
Re-exports§
use std::sync::Mutex;🔒use std::sync::MutexGuard;🔒use std::sync::PoisonError;🔒use std::sync::RwLock;🔒use std::sync::RwLockReadGuard;🔒use std::sync::RwLockWriteGuard;🔒