9 releases

0.1.7 Jul 6, 2023
0.1.6 Jun 21, 2023
0.1.5 Mar 28, 2023
0.1.1 Feb 23, 2023
0.0.1 Feb 18, 2023

#793 in Concurrency

Download history 748/week @ 2023-12-16 435/week @ 2023-12-23 641/week @ 2023-12-30 882/week @ 2024-01-06 827/week @ 2024-01-13 966/week @ 2024-01-20 1195/week @ 2024-01-27 1360/week @ 2024-02-03 731/week @ 2024-02-10 737/week @ 2024-02-17 907/week @ 2024-02-24 1235/week @ 2024-03-02 1089/week @ 2024-03-09 1492/week @ 2024-03-16 1327/week @ 2024-03-23 822/week @ 2024-03-30

4,892 downloads per month
Used in 12 crates (via eyeball)

MPL-2.0 license

17KB
232 lines

readlock

(Shared) Read-Only Lock: A thing that can be useful when you don't really want shared mutability, you just want to mutate a value from one place and read it from many others.

This library provides three types:

  • Shared<T>: similar to Arc<RwLock<T>>, but you can only create SharedReadLock<T>s and WeakReadLock<T>s from it that share access to the same inner value, not further Shared<T>s. Also, acquiring a write lock requires unique ownership / borrowing (&mut self). However: Reading requires no locking because mutably borrowing the Shared means that no other thread can be mutating the value at the same time (all other reference to the value are read-only).
  • SharedReadLock<T>: like a Arc<RwLock<T>> that is only ever used for reading. Can be downgraded to WeakReadLock.
  • WeakReadLock<T>: like a Weak<RwLock<T>>. That is, it references the same memory, but if the original Shared and any derived SharedReadLocks to that value are dropped, it will be deallocated regardless of any WeakReadLocks. Must be upgraded into SharedReadLock to access the inner value.

Dependencies

~15KB