https://github.com/cppcoffee/sharelock-rs
A spin reader-writer lock.
https://github.com/cppcoffee/sharelock-rs
Last synced: 10 months ago
JSON representation
A spin reader-writer lock.
- Host: GitHub
- URL: https://github.com/cppcoffee/sharelock-rs
- Owner: cppcoffee
- Created: 2021-05-19T04:58:29.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-05-19T15:26:06.000Z (about 5 years ago)
- Last Synced: 2025-01-29T00:46:57.282Z (over 1 year ago)
- Language: Rust
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# sharedlock-rs
## Introduce
ShareLock is a spin read/write lock library implemented using rust.
The RAII guards returned from the locking methods implement Deref (and DerefMut for the write methods) to allow access to the content of the lock.
## Examples
```rust
use sharedlock_rs::SharedLock;
let lock = SharedLock::new(5);
{
let r1 = lock.read().unwrap();
let r2 = lock.read().unwrap();
assert_eq!(*r1, 5);
assert_eq!(*r2, 5);
}
{
let mut w = lock.write().unwrap();
*w += 1;
assert_eq!(*w, 6);
}
```
## Reference
[https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock](https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock)