#mutex #synchronization #lock #parking-lot #sync #locking

simple-mutex

A mutex more efficient than std and simpler than parking_lot

8 stable releases

1.1.5 May 27, 2020
1.1.4 May 26, 2020
1.1.1 May 25, 2020
1.0.1 May 23, 2020

#1084 in Concurrency

Download history 18157/week @ 2023-11-29 15249/week @ 2023-12-06 13362/week @ 2023-12-13 9147/week @ 2023-12-20 8165/week @ 2023-12-27 8933/week @ 2024-01-03 11461/week @ 2024-01-10 11518/week @ 2024-01-17 11714/week @ 2024-01-24 11618/week @ 2024-01-31 12260/week @ 2024-02-07 11918/week @ 2024-02-14 12083/week @ 2024-02-21 12755/week @ 2024-02-28 14667/week @ 2024-03-06 10056/week @ 2024-03-13

51,823 downloads per month
Used in 4 crates (2 directly)

Apache-2.0 OR MIT

14KB
170 lines

simple-mutex

Build License Cargo Documentation

A simple mutex.

More efficient than std::sync::Mutex and simpler than parking_lot::Mutex.

The locking mechanism uses eventual fairness to ensure locking will be fair on average without sacrificing performance. This is done by forcing a fair lock whenever a lock operation is starved for longer than 0.5 milliseconds.

Examples

use simple_mutex::Mutex;
use std::sync::Arc;
use std::thread;

let m = Arc::new(Mutex::new(0));
let mut threads = vec![];

for _ in 0..10 {
    let m = m.clone();
    threads.push(thread::spawn(move || {
        *m.lock() += 1;
    }));
}

for t in threads {
    t.join().unwrap();
}
assert_eq!(*m.lock(), 10);

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~130KB