qrwlock

Crates.ioqrwlock
lib.rsqrwlock
version0.2.0
sourcesrc
created_at2022-12-21 18:52:59.803668
updated_at2022-12-21 20:33:38.050455
descriptionFair queued read-write lock
homepage
repositoryhttps://github.com/pskrgag/rust-qrwlock
max_upload_size
id743373
size17,180
Pavel Skripkin (pskrgag)

documentation

README

Queued rwlock implementation in Rust

This read-write lock uses ticket mutex as waitqueue, which acts like FIFO. It allows to avoid unfairness and starvation of readers or writes, that is common problem for generic rwlocks (read-preffered or write-preffered)

Example

extern crate qrwlock;
use std::{sync::Arc, thread};

fn main() {
    let counter = Arc::new(qrwlock::RwLock::new(0));

    let thread = thread::spawn({
        let counter = counter.clone();
        move || {
            for _ in 0..1000 {
                *counter.write() += 1;
            }
        }
    });

    for _ in 0..1000 {
        println!("read {}", *counter.read());
    }

    thread.join().unwrap();

    assert_eq!(*counter.read(), 1000);
}

License

qrwlock is distributed under the MIT License, (See LICENSE).

Commit count: 7

cargo fmt