Inside Rust's std and parking_lot mutexes – who wins?

Rust’s lock showdown: tiny speed demon vs safe old guard

TLDR: A Rust deep-dive compares the built-in lock with the popular parking_lot, promising real benchmarks. The comments explode: the parking_lot creator touts tiny locks, others say std can’t swap due to safety and platform constraints, and one camp says ditch locks entirely for friendlier tools.

Rust devs love a good lock, and this piece dives into the two big options: the standard library’s mutex (a built‑in “keep things from colliding” lock) vs parking_lot (the fan‑favorite speedster). But the comments? Absolute fireworks. The creator of WTF::ParkingLot pops in, side‑eyeing the Linux‑only benchmarks and bragging about tiny locks — “we pack a 2‑bit lock into every object!” That’s the vibe: small and fast means you can sprinkle locks everywhere without bloating memory.

Then the lore drops: a commenter links a giant Rust saga explaining why std can’t just copy parking_lot — cross‑platform promises and poisoning (locks marked “unsafe” after a crash) make swaps messy. The debate turns spicy: one camp calls poisoning “a design flaw,” another defends fail‑fast safety so bugs don’t quietly corrupt data. Meanwhile, the hottest take lands like a grenade: skip locks altogether. Use queues (send messages instead of sharing data) or RCU (a clever copy‑on‑update trick) for developer sanity.

Links fly — the issue thread and the WebKit blog — plus memes: “poisoned locks = toxic ex,” “2‑bit locks = diet mutex.” Verdict from the crowd: show more platforms, keep the benchmarks coming, and help us pick between performance, portability, and peace of mind.

Key Points

  • The article compares Rust’s std::sync::Mutex to parking_lot::Mutex through source-level teardown and benchmarks.
  • It examines std::sync::Mutex as implemented in Rust v1.90.0 and parking_lot::Mutex in parking_lot v0.12.5.
  • Benchmarks aim to quantify performance, memory footprint, and behavior under contention for both mutexes.
  • The piece explains mutex fundamentals, critical sections, and safe usage patterns.
  • It provides a decision guide to help developers choose between std and parking_lot mutexes based on findings.

Hottest takes

"we stuff a 2-bit lock into every object header" — pizlonator
"This is one of the biggest design flaws in Rust's std" — kouteiheika
"don’t use mutexes at all" — kccqzy
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.
Inside Rust's std and parking_lot mutexes – who wins? - Weaving News | Weaving News