#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

#1154 in Concurrency

Download history 14802/week @ 2024-04-08 14969/week @ 2024-04-15 13971/week @ 2024-04-22 11243/week @ 2024-04-29 11071/week @ 2024-05-06 18488/week @ 2024-05-13 16957/week @ 2024-05-20 14876/week @ 2024-05-27 14114/week @ 2024-06-03 14621/week @ 2024-06-10 16435/week @ 2024-06-17 12211/week @ 2024-06-24 13240/week @ 2024-07-01 11635/week @ 2024-07-08 14299/week @ 2024-07-15 13243/week @ 2024-07-22

53,336 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

~135KB