qutex

Crates.ioqutex
lib.rsqutex
version0.2.6
sourcesrc
created_at2017-03-11 08:40:03.097762
updated_at2024-03-25 16:29:24.102569
descriptionSynchronization mechanisms that rely on lock-free and other non-(thread)blocking techniques, such as Rust futures, to guarantee mutually exclusive or shared exclusive access to data.
homepagehttps://github.com/cogciprocate/qutex
repositoryhttps://github.com/cogciprocate/qutex
max_upload_size
id8928
size62,063
Nick Sanders (c0gent)

documentation

https://docs.rs/qutex

README

Qutex

Non-thread-blocking queue-backed data locks based on Rust futures.

Includes futures capable versions of Mutex and RwLock.

Documentation

Example

Cargo.toml:

[dependencies]
qutex = "0.2"

main.rs:

extern crate qutex;
extern crate futures;

use std::thread;
use futures::Future;
use qutex::Qutex;

fn main() {
    let thread_count = 100;
    let mut threads = Vec::with_capacity(thread_count);
    let start_val = 0;
    let qutex = Qutex::new(start_val);

    for _ in 0..thread_count {
        let future_val = qutex.clone().lock();

        let future_add = future_val.map(|mut val| {
            *val += 1;
        });

        threads.push(thread::spawn(|| {
            future_add.wait().unwrap();
        }));
    }

    for thread in threads {
        thread.join().unwrap();
    }

    let val = qutex.lock().wait().unwrap();
    assert_eq!(*val, start_val + thread_count);
    println!("Qutex final value: {}", *val);
}

Commit count: 84

cargo fmt