Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 

rlu-rs: Read-Log-Update in Rust

This library is an implementation of the Read-Log-Update lock-free concurrency mechanism in Rust. See the SOSP'15 paper and the Morning Paper summary for details on the algorithm.

use std::sync::Arc;
use rlu::{Rlu, RluObject};
use std::{thread, time};

fn main() {
  let rlu: Arc<Rlu<u64>> = Arc::new(Rlu::new());
  let obj: RluObject<u64> = rlu.alloc(1);

  let reader = {
    let rlu = rlu.clone();
    thread::spawn(move || {
      let thread = rlu.thread();
      let mut session = thread.session();
      let n: *const u64 = session.read_lock(obj);
      let n2 = unsafe { *n };
      thread::sleep(time::Duration::from_millis(100));
      assert_eq!(unsafe { *n }, n2);
    })
  };

  let writer = {
    let rlu = rlu.clone();
    thread::spawn(move || {
      let thread = rlu.thread();
      loop {
        let mut session = thread.session();
        match session.write_lock(obj) {
          Some(n) => {
            unsafe { *n += 1; }
            break;
          },
          None => {
            session.abort();
          }
        }
      }
    })
  };

  reader.join().unwrap();
  writer.join().unwrap();
}

About

A Rust implementation of the Read-Log-Update concurrency mechanism

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages