@@ -4,8 +4,8 @@ minutes: 14
44
55# ` Mutex `
66
7- [ ` Mutex<T> ` ] [ 1 ] ensures mutual exclusion _ and_ allows mutable access to ` T `
8- behind a read-only interface (another form of
7+ [ ` Mutex<T> ` ] ensures mutual exclusion _ and_ allows mutable access to ` T ` behind
8+ a read-only interface (another form of
99[ interior mutability] ( ../../borrowing/interior-mutability.md ) ):
1010
1111``` rust,editable
@@ -27,9 +27,7 @@ fn main() {
2727Notice how we have a [ ` impl<T: Send> Sync for Mutex<T> ` ] [ 2 ] blanket
2828implementation.
2929
30- [ 1 ] : https://doc.rust-lang.org/std/sync/struct.Mutex.html
3130[ 2 ] : https://doc.rust-lang.org/std/sync/struct.Mutex.html#impl-Sync-for-Mutex%3CT%3E
32- [ 3 ] : https://doc.rust-lang.org/std/sync/struct.Arc.html
3331
3432<details >
3533
@@ -41,13 +39,15 @@ implementation.
4139 ` MutexGuard ` ensures that the ` &mut T ` doesn't outlive the lock being held.
4240- ` Mutex<T> ` implements both ` Send ` and ` Sync ` if and only if ` T ` implements
4341 ` Send ` .
44- - A read-write lock counterpart: ` RwLock ` .
42+ - Rust has a multi-reader single-writer lock counterpart: [ ` RwLock<T> ` ] .
4543- Why does ` lock() ` return a ` Result ` ?
4644 - If the thread that held the ` Mutex ` panicked, the ` Mutex ` becomes "poisoned"
4745 to signal that the data it protected might be in an inconsistent state.
4846 Calling ` lock() ` on a poisoned mutex fails with a [ ` PoisonError ` ] . You can
4947 call ` into_inner() ` on the error to recover the data regardless.
5048
51- [ `PoisonError` ] : https://doc.rust-lang.org/std/sync/struct.PoisonError.html
52-
5349</details >
50+
51+ [ `Mutex<T>` ] : https://doc.rust-lang.org/std/sync/struct.Mutex.html
52+ [ `RwLock<T>` ] : https://doc.rust-lang.org/std/sync/struct.RwLock.html
53+ [ `PoisonError` ] : https://doc.rust-lang.org/std/sync/struct.PoisonError.html
0 commit comments