Surelock: Deadlock-Free Mutexes for Rust
Published: 2026-04-11
NOTE Hello r/rust ! Thank you for the interest in this work and for the delightful conversation ❤️ I hate deadlocks. Maybe you do too. Back at Fission , whenever someone would suggest a mutex we’d start a chant of “I say mutex, you say deadlock: Mutex! DEADLOCK! Mutex! DEADLOCK!“. Deadlocks lurk — perfectly invisible in code review, happy to pass CI a thousand times, then lock your system up at 3am under a request pattern that no one anticipated. They have their own tradeoffs, but I miss TVar s from Haskell. AFAICT there’s no way to do proper TVar s in languages that have no way to enforce purity. We “should” prefer lock-free programming, but mutexes are very common in the Rust standard style. I often hear that actors eliminate deadlocks, but as someone who’s written her fair share of Elixir , this is 100% a lie (though they are less frequent). Rust famously catches data races at compile time, but for deadlocks? You get a Mutex , a pat on the back, and “good luck, babe”. There are some tools that help analyze your code that are fairly good, but I want feedback during development. I’ve been thinking about a better approach to this problem for a while, looked at a bunch of other attempts and have come up with what I hope is a decent ergonomic balance that covers many common use cases in Rust: surelock , a deadlock-freedom library. If your code compiles, it doesn’t deadlock. No Result , no Option , no runtime panic on the lock path. Every acquisition is either proven safe by the…
Originally sourced from Hacker News