libmcs-0.1.0 doesn't have any documentation.
libmcs
This Rust library provides a mutex api using MCS lock algorithm.
Examples
These examples are taken from the documentation of std::sync::Mutex
.
It shows that mcs::Mutex
can be interchangebly used with std::sync::Mutex
.
extern crate libmcs;
use Arc;
use thread;
use channel;
use Mutex;
const N: usize = 10;
// Spawn a few threads to increment a shared variable (non-atomically), and
// let the main thread know once all increments are done.
//
// Here we're using an Arc to share memory among threads, and the data inside
// the Arc is protected with a mutex.
let data = new;
let = channel;
for _ in 0..10
rx.recv.unwrap;
// Recovering from a poisoned mutex
extern crate libmcs;
use Arc;
use thread;
use Mutex;
let lock = new;
let lock2 = lock.clone;
let _ = spawn.join;
// The lock is poisoned by this point, but the returned result can be
// pattern matched on to return the underlying guard on both branches.
let mut guard = match lock.lock ;
*guard += 1;
About MCS lock
A queue-based spin lock such as MCS lock is said to provide a better scalability than a simple spin lock because of its distributed nature. However, a drawback of MCS lock is that it traditonally required to pass an explicit arguement, whose type is a pointer to a queue node. In Rust syntax, the canonical MCS lock API will look like the following:
;
;
However, the api of this crate does not pose such restriction because LockGuard
implicitly
takes care of the queue node. Therefore, it can be used in place of std::sync::Mutex
.