Skip to content

cppcoffee/sharelock-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sharedlock-rs

Introduce

ShareLock is a spin read/write lock library implemented using rust.

The RAII guards returned from the locking methods implement Deref (and DerefMut for the write methods) to allow access to the content of the lock.

Examples

use sharedlock_rs::SharedLock;

let lock = SharedLock::new(5);

{
    let r1 = lock.read().unwrap();
    let r2 = lock.read().unwrap();
    assert_eq!(*r1, 5);
    assert_eq!(*r2, 5);
}

{
    let mut w = lock.write().unwrap();
    *w += 1;
    assert_eq!(*w, 6);
}

Reference

https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock

About

A spin reader-writer lock.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages