rculock

A synchronization primitive for lock-free reads with one concurrent writer

MIT License

Downloads
3.3K
Stars
21
  • rculock
    A [[https://en.wikipedia.org/wiki/Read-copy-update][read-copy-update]] lock using [[https://github.com/aturon/crossbeam][crossbeam]].

The API is similar to =std::sync::RwLock=. Readers are lock-free and can exist concurrently with a writer, which updates the data protected by the lock only when the write guard is dropped.

This crate should currently be usable, but isn't a very efficient implementation (see [[https://github.com/nivekuil/rculock/issues/1][#1]]).

See [[https://docs.rs/rculock/][documentation]] for more details.

** Usage #+BEGIN_SRC toml [dependencies] rculock = "0.1" #+END_SRC *** Examples #+BEGIN_SRC rust use rculock::{RcuLock, RcuGuard};

// Create a new RcuLock protecting a piece of data, in this case a number (u32). let data: RcuLock = RcuLock::new(5); assert_eq!(5, *data.read()); { // The data is cloned and handed to the writer let mut guard: RcuGuard = data.write(); // RcuGuard implements Deref and DerefMut for easy access to the data. *guard = 4; // The writer has changed its copy of the data, but the changes // have not yet made it back to the master RcuLock. assert_eq!(5, *data.read()); } // After the write guard is dropped, the state of the resource // as the writer sees it is atomically stored back into the master RcuLock. assert_eq!(4, *data.read()); #+END_SRC