talira

parking_lot

Compact, fast mutexes, read-write locks and condition variables for Rust

open sourceMIT OR Apache-2.0free

parking_lot is a Rust crate by Amanieu d'Antras with compact, fast versions of the standard synchronization primitives: Mutex, RwLock, RecursiveRwLock, Condvar, Once and ReentrantMutex. A Mutex or Once takes one byte and a Condvar or RwLock one word, uncontended locking is a single atomic operation, and locks spin briefly before parking the thread. Thread queuing lives in a shared parking lot (after WebKit's WTF::ParkingLot), and its lock_api and parking_lot_core crates let you build your own primitives.

Problems it solves

  • make lock contention cheaper in my multithreaded Rust program
  • use smaller, faster mutexes than the Rust standard library's
  • upgrade a read lock to a write lock in Rust without releasing it

Features

  • Mutex and Once in 1 byte, Condvar and RwLock in 1 word
  • Uncontended lock and unlock in a single atomic operation
  • Adaptive spinning before parking the thread
  • Task-fair RwLock with downgradable and upgradable read locks
  • Condvar without spurious wakeups
  • Optional deadlock detection and serde support

Limitations

  • Its deadlock detector is experimental and disabled by default1

Alternatives

The same job

These do what parking_lot does.

  1. DashMap Blazing fast concurrent HashMap for Rust
  2. Crossbeam Tools for concurrent programming in Rust: channels, queues, atomics and scoped threads

Compare parking_lot with the top 3