#atomic #lock-free

loom

Permutation testing for concurrent code

14 releases

✓ Uses Rust 2018 edition

new 0.2.10 Oct 16, 2019
0.2.9 Oct 9, 2019
0.2.8 Sep 30, 2019
0.2.4 Aug 20, 2019
0.0.1 Dec 7, 2018

#18 in Concurrency

Download history 4817/week @ 2019-07-03 5084/week @ 2019-07-10 5169/week @ 2019-07-17 5565/week @ 2019-07-24 5549/week @ 2019-07-31 6234/week @ 2019-08-07 7322/week @ 2019-08-14 6726/week @ 2019-08-21 6559/week @ 2019-08-28 7594/week @ 2019-09-04 7208/week @ 2019-09-11 8158/week @ 2019-09-18 8027/week @ 2019-09-25 8301/week @ 2019-10-02 8529/week @ 2019-10-09

29,943 downloads per month
Used in 3 crates

MIT license

135KB
3.5K SLoC

Loom

Loom is a testing tool for concurrent Rust code. It runs a test many times, permuting the possible concurrent executions of that test under the C11 memory model. It uses state reduction techniques to avoid combinatorial explosion.

Build Status

Documentation

Getting started

To use loom, first add this to your Cargo.toml:

[dev-dependencies]
loom = "0.2.10"

Next, create a test file and add a test:

use loom::sync::Arc;
use loom::sync::atomic::AtomicUsize;
use loom::sync::atomic::Ordering::{Acquire, Release, Relaxed};
use loom::thread;

#[test]
#[should_panic]
fn buggy_concurrent_inc() {
    loom::model(|| {
        let num = Arc::new(AtomicUsize::new(0));

        let ths: Vec<_> = (0..2)
            .map(|_| {
                let num = num.clone();
                thread::spawn(move || {
                    let curr = num.load(Acquire);
                    num.store(curr + 1, Release);
                });
            })
            .collect();

        for th in ths {
            th.join().unwrap();
        }

        assert_eq!(2, num.load(Relaxed));
    });
}

Overview

Loom is an implementation of techniques described in CDSChecker: Checking Concurrent Data Structures Written with C/C++ Atomics.

Thread ordering

TODO

Atomics

In the C++11 memory model, stores to a single atomic cell are totally ordered. This is the modification order. Loom permutes the modification order of each atomic cell within the bounds of the coherence rules.

Limitations

While already very useful, loom is in its early stages and has a number of limitations.

  • Execution is slow (#5).
  • The full C11 memory model is not implemented (#6).
  • No fence support (#7).

License

This project is licensed under the MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in loom by you, shall be licensed as MIT, without any additional terms or conditions.

Dependencies

~140–770KB
~16K SLoC