[−][src]Crate async_mutex
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);
Structs
Mutex | An async mutex. |
MutexGuard | A guard that releases the mutex when dropped. |