Go to file
Stjepan Glavina 463ae0ea93 Initial commit 2020-05-27 21:31:05 +02:00
.github Initial commit 2020-05-27 21:31:05 +02:00
src Initial commit 2020-05-27 21:31:05 +02:00
tests Initial commit 2020-05-27 21:31:05 +02:00
.gitignore Initial commit 2020-05-27 21:31:05 +02:00
CHANGELOG.md Initial commit 2020-05-27 21:31:05 +02:00
Cargo.toml Initial commit 2020-05-27 21:31:05 +02:00
LICENSE-APACHE Initial commit 2020-05-27 21:31:05 +02:00
LICENSE-MIT Initial commit 2020-05-27 21:31:05 +02:00
README.md Initial commit 2020-05-27 21:31:05 +02:00

README.md

async-mutex

Build License Cargo Documentation

An async 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 async_mutex::Mutex;
use smol::Task;
use std::sync::Arc;

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

for _ in 0..10 {
    let m = m.clone();
    tasks.push(Task::spawn(async move {
        *m.lock().await += 1;
    }));
}

for t in tasks {
    t.await;
}
assert_eq!(*m.lock().await, 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.