1
0
Fork
You've already forked readlock
0
A weird alternative to Arc<RwLock<T>>
  • Rust 100%
2026年02月06日 12:30:22 +01:00
.cargo Replace GitHub actions by xtask 2026年01月10日 23:05:09 +01:00
.vscode Add lite module 2023年06月14日 14:15:58 +02:00
readlock Publish readlock v0.1.11 and readlock-tokio v0.1.6 2026年02月06日 12:30:22 +01:00
readlock-tokio Publish readlock v0.1.11 and readlock-tokio v0.1.6 2026年02月06日 12:30:22 +01:00
xtask Replace GitHub actions by xtask 2026年01月10日 23:05:09 +01:00
.gitignore Initial commit 2023年02月19日 00:39:44 +01:00
.rustfmt.toml Initial commit 2023年02月19日 00:39:44 +01:00
Cargo.toml Update package metadata 2026年01月10日 23:07:18 +01:00
LICENSE Initial commit 2023年02月19日 00:39:44 +01:00
README.md Upgrade rclite 2023年06月21日 10:42:47 +02:00

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.