tokio-lk version - 0.1.1
Tokio-lk
** A lock-by-id future for tokio **
Lock
future will return Guard
once it gets the mutex.
to hold the lock in subsequent futures, move the Guard
inside the future output.
to release the mutex, simply drops the Guard
from your future chain.
Each Lock
object is assigned an unique id.
The uniqueness is promised until USIZE_MAX of id gets generated.
Make sure old Locks are dropped before you generate new Locks above this amount.
Example:
use HashMap;
use ;
use ;
use *;
use *;
use Runtime;
use Delay;
let mut rt = new.unwrap;
let map = new;
let now = now;
// this task will compete with task2 for lock at id 1
let task1 = fnew
.and_then
.and_then
.and_then;
// this task will compete with task1 for lock at id 1
let task2 = fnew
.and_then
.and_then
.and_then;
// no other task compete for lock at id 2
let task3 = fnew
.and_then
.and_then
.and_then;
rt.block_on.unwrap;
Benchmark
to run the benchmark, execute the following command in the prompt:
The lock1000_parallel
benchmark is to run 1000 futures locked by a single lock to update the
counter.
The lock1000_serial
benchmark is to run run similar operations in a single thread.
Currently our implementation is about 8 times slower than the single threaded version.
License
Licensed under
- MIT license (LICENSE-MIT or https://opensource.org/licences/MIT)
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, shall be licensed as above, without any additional terms or conditions.