The fast async mutex which uses atomics with spinlock algorithm.
Spinlock algorithm integrated with the Rust futures concept without the overhead of any libs. Also when the MutexGuard
is dropped,
a waker of the next locker will be executed.
It will be works with any async runtime in Rust
, it may be a tokio
, smol
, async-std
and etc..
```rust use fastasyncmutex::mutex::Mutex;
async fn main() { let mutex = Mutex::new(10); let guard = mutex.lock().await; assert_eq!(*guard, 10); } ```
There is result of benchmarks which runs on MacBook Pro (16-inch, 2019) 2,3 GHz 8-Core Intel Core i9 16GB RAM
Tests you can find in the benchmarks dir.
```
running 12 tests
test fastasyncmutex::tests::concurrencywithoutwaiting ... bench: 1,579,327 ns/iter (+/- 122,787)
test fastasyncmutex::tests::create ... bench: 0 ns/iter (+/- 0)
test fastasyncmutex::tests::stepbystepwithoutwaiting ... bench: 194,037 ns/iter (+/- 18,457)
test futures::tests::concurrencywithoutwaiting ... bench: 1,623,903 ns/iter (+/- 198,099)
test futures::tests::create ... bench: 84 ns/iter (+/- 20)
test futures::tests::stepbystepwithoutwaiting ... bench: 205,545 ns/iter (+/- 11,437)
test smol::tests::concurrencywithoutwaiting ... bench: 1,813,222 ns/iter (+/- 88,291)
test smol::tests::create ... bench: 0 ns/iter (+/- 0)
test smol::tests::stepbystepwithoutwaiting ... bench: 329,124 ns/iter (+/- 33,841)
test tokio::tests::concurrencywithoutwaiting ... bench: 22,625,869 ns/iter (+/- 6,185,517)
test tokio::tests::create ... bench: 98 ns/iter (+/- 54)
test tokio::tests::stepbystepwithoutwaiting ... bench: 718,106 ns/iter (+/- 157,179)
test result: ok. 0 passed; 0 failed; 0 ignored; 12 measured; 0 filtered out ```
Licensed under either of
at your option.
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.