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|
#345 in Concurrency
486 downloads per month
Used in 161 crates (3 directly)
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
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
The library also provides some other useful APIs, like a
utilities for building your own internally poisoned interior mutability types
poison module (these are used in the implementation of
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
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
with the rest of your dependencies:
[dependencies] shared-mutex = "0.2"
Jonathan Reem is the primary author and maintainer of shared-mutex.