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

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

18 releases

0.2.6 Mar 25, 2024
0.2.4 Aug 21, 2022
0.2.3 Apr 19, 2019
0.2.2 Mar 8, 2019
0.0.5 Mar 26, 2017

#279 in Concurrency

Download history 1029/week @ 2023-12-24 888/week @ 2023-12-31 1262/week @ 2024-01-07 1110/week @ 2024-01-14 861/week @ 2024-01-21 1195/week @ 2024-01-28 1353/week @ 2024-02-04 1510/week @ 2024-02-11 1700/week @ 2024-02-18 1627/week @ 2024-02-25 1369/week @ 2024-03-03 1895/week @ 2024-03-10 1477/week @ 2024-03-17 1829/week @ 2024-03-24 1298/week @ 2024-03-31 894/week @ 2024-04-07

5,566 downloads per month
Used in 48 crates (3 directly)

MIT license

54KB
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

~155–315KB