#future #mutex #lock #async #data-structures #lock-free-queue

bastion-qutex

Synchronization 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

2 unstable releases

0.2.4 Nov 13, 2019
0.0.0 Nov 13, 2019

#1186 in Concurrency

Download history 4/week @ 2024-07-28 13/week @ 2024-08-04 9/week @ 2024-08-11 3/week @ 2024-08-18 6/week @ 2024-08-25 9/week @ 2024-09-01 10/week @ 2024-09-08 12/week @ 2024-09-15 30/week @ 2024-09-22 37/week @ 2024-09-29 10/week @ 2024-10-06 13/week @ 2024-10-13 6/week @ 2024-10-20 10/week @ 2024-10-27 43/week @ 2024-11-03

74 downloads per month

MIT license

52KB
1K SLoC

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);
}

Dependencies

~445–590KB