Skip to content

Lock poisoning

Category: Synchronization · Status: stub · Lessons: chapter 03, When locks go wrong (planned)

One line: Marking a lock as suspect when a thread panics while holding it, so that the next thread to take it learns the data may be half-updated.

Also called: poisoned mutex, abandoned mutex.

How it connects

In each language

Rust Mutex: a panic while holding the guard poisons it and later lock calls return an error, until clear_poison (Rust 1.77); Once is poisoned the same way
Go No poisoning: Mutex.Lock returns no value that could report a panic
Java No poisoning: a synchronized statement ↗ unlocks the monitor when its block completes abruptly for any reason
C# AbandonedMutexException is thrown when a thread acquires a Mutex that another thread abandoned by exiting without releasing it
The operating system POSIX robust mutexes: pthread_mutex_lock returns EOWNERDEAD when the owner terminated while holding it, and pthread_mutex_consistent marks the state consistent again

Where to read more