Mutex poisoning is not for everyone
Web page · https://bertptrs.nl/2026/11/16/mutex-poisoning-is-not-for-everyone.html
First seen by Oriel on .
AI summary
This Rust blog argues that default Mutex poisoning imposes ubiquitous code-size, performance, and readability costs, and advocates stabilising std::sync::nonpoison::Mutex while keeping poisoning opt-in.
- Uncontended Rust mutex locking uses a single atomic operation, while poisoning adds an AtomicBool and can increase each mutex’s size by zero bytes to an additional pointer.
- A check_contents example compiles to 147 assembly lines with lock().unwrap(), 68 with PoisonError::into_inner, and 34 using nightly non-poisoning mutexes.
- The author argues poisoning cannot generally be optimized away because mutexes must track poison state, unlike bounds checks that compilers can sometimes eliminate.
- Poisoning is useful for critical sections protecting invariants, but most mutex uses involve simple assignments or no invalid intermediate state.
- The proposed direction is to stabilize std::sync::nonpoison::Mutex, retain poisoning as an additive wrapper, and avoid making std::sync::Mutex panic by default.
#rust #mutexes #concurrency #performance
Generated by gpt-5.6-sol. Check the original for details.
Metric trends
Last 30 days · Up to 120 recorded samples per source and metric, with reposts kept separate · First and latest retained
Points
Score reported by the source.
- Hacker News: 19, latest observation ; +16 over observed period since
- Lobsters: 38, latest observation ; +37 over observed period since
Comments
Comment count reported by the source.
- Hacker News: 4, latest observation ; +4 over observed period since
- Lobsters: 63, latest observation ; +63 over observed period since
Aliases
| Source | External ID | URL |
|---|---|---|
| Hacker News | 50589701 | https://bertptrs.nl/2026/11/16/mutex-poisoning-is-not-for-everyone.html Read discussion |
| Lobsters | uzn2t6 | https://bertptrs.nl/2026/11/16/mutex-poisoning-is-not-for-everyone.html Read discussion |