7 releases

Uses old Rust 2015

0.3.1 Jun 2, 2016
0.3.0 Feb 16, 2016
0.2.3 Feb 12, 2016
0.1.0 Feb 6, 2016

#1132 in Concurrency

Download history 185/week @ 2024-03-13 387/week @ 2024-03-20 530/week @ 2024-03-27 191/week @ 2024-04-03 217/week @ 2024-04-10 201/week @ 2024-04-17 210/week @ 2024-04-24 247/week @ 2024-05-01 208/week @ 2024-05-08 215/week @ 2024-05-15 202/week @ 2024-05-22 168/week @ 2024-05-29 193/week @ 2024-06-05 232/week @ 2024-06-12 289/week @ 2024-06-19 153/week @ 2024-06-26

873 downloads per month
Used in 201 crates (3 directly)

MIT license

734 lines


A reader-writer lock that can be used with a Condvar.


Reader writer locks can be more efficient than mutual exclusion locks in cases where many operations require read-only access to the data, as they can significantly lower contention by allowing multiple readers to proceed at once.

As a result, most operating system's native libraries come with a reader-writer lock implementation in addition to mutual exclusion locks. However, on unix systems, this reader-writer lock (which is used in std::sync::RwLock) cannot be associated with a condition variable, which are limited to the native mutex (which is used in std::sync::Mutex). On Windows the native reader-writer lock supports waiting on a condition variable but this functionality is not yet exposed in the standard library.

SharedMutex is an implementation of a reader-writer lock without this (and other) restrictions - shared mutex guards provide methods for waiting on condition variables. In addition to this extremely useful new API, this crate also features some useful combinators, such as mapped guards, and removes other restrictions by making the guard types Send and Sync.

The library also provides some other useful APIs, like a RawSharedMutex and utilities for building your own internally poisoned interior mutability types in the poison module (these are used in the implementation of SharedMutex).


The locking strategy has been adapted from the implementation of std::shared_mutex from libc++ in llvm, and has the same fairness and starvation guarantees (readers cannot starve writers, waiting writers block readers).

I have carefully reviewed the code for safety in addition to using automated tests, but as with all concurrent and unsafe code, more eyes and brains would be better.


Use the crates.io repository; add this to your Cargo.toml along with the rest of your dependencies:

shared-mutex = "0.2"


Jonathan Reem is the primary author and maintainer of shared-mutex.