10 releases

0.1.8 Jul 13, 2024
0.1.7 Jul 6, 2023
0.1.6 Jun 21, 2023
0.1.5 Mar 28, 2023
0.0.1 Feb 18, 2023

#168 in Concurrency

Download history 1140/week @ 2024-08-19 1155/week @ 2024-08-26 1302/week @ 2024-09-02 1188/week @ 2024-09-09 1287/week @ 2024-09-16 1563/week @ 2024-09-23 1457/week @ 2024-09-30 1413/week @ 2024-10-07 1796/week @ 2024-10-14 926/week @ 2024-10-21 1098/week @ 2024-10-28 1390/week @ 2024-11-04 1208/week @ 2024-11-11 1316/week @ 2024-11-18 1871/week @ 2024-11-25 1486/week @ 2024-12-02

5,995 downloads per month
Used in 18 crates (via eyeball)

MPL-2.0 license

19KB
255 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