2 unstable releases

0.2.0 Dec 21, 2022
0.1.0 Dec 21, 2022

#1054 in Concurrency

MIT license

14KB
289 lines

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).


lib.rs:

This crate provides fair read-write lock, that does not prone to reader or writer stravations

Dependencies

~190KB