#mutex #lock #synchronization #parking-lot

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

#161 in Concurrency

Download history 12092/week @ 2021-08-08 11913/week @ 2021-08-15 14069/week @ 2021-08-22 11278/week @ 2021-08-29 11766/week @ 2021-09-05 11033/week @ 2021-09-12 11977/week @ 2021-09-19 12397/week @ 2021-09-26 11476/week @ 2021-10-03 13270/week @ 2021-10-10 10236/week @ 2021-10-17 11025/week @ 2021-10-24 10078/week @ 2021-10-31 11677/week @ 2021-11-07 11333/week @ 2021-11-14 14351/week @ 2021-11-21

34,859 downloads per month
Used in 107 crates (via async-dup)

Apache-2.0 OR MIT

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

~34KB