Skip to main content


#rust question: When is it still a good idea to use parking_lot rather than the standard library's Mutex, RwLock, and so on? My understanding is that parking_lot became much less necessary when Rust 1.62.0 introduced thinner, faster mutexes on Linux, and 1.63.0 made the constructors const. And if one only has a small number of mutexes, I suppose the overhead of the parking lot would dominate. Has anyone written a post in the past year or so weighing the pros and cons?
#rust

modulux reshared this.

in reply to Matt Campbell

Correct. parking_lot’s remaining advantage is in more powerful and flexible API, e.g. rwlock downgrades or control over fair/unfair locking.
in reply to Matt Campbell

appears to be some benchmarks on a tracking issue:
https://github.com/rust-lang/rust/pull/95035#issuecomment-1073966631

TL;DR doing better in the no/light contention categories, ~100us worse than parking lot, impoved from 2ms worse before the changes. Outperforms everything they tests in heavy/extreme contention

Going off that i think std sounds like a good default, the only performance situation I can think of are massive datasets where the lock is more expensive than the calculation performed. That or having unpoisoned locks