#atomic #lock-free

loom

Permutation testing for concurrent code

31 releases

0.5.2 Oct 7, 2021
0.5.1 Jul 2, 2021
0.5.0 Apr 12, 2021
0.4.0 Dec 3, 2020
0.0.1 Dec 7, 2018

#12 in Concurrency

Download history 10666/week @ 2021-07-01 8452/week @ 2021-07-08 9372/week @ 2021-07-15 8785/week @ 2021-07-22 9703/week @ 2021-07-29 9916/week @ 2021-08-05 9428/week @ 2021-08-12 10331/week @ 2021-08-19 10093/week @ 2021-08-26 8239/week @ 2021-09-02 10413/week @ 2021-09-09 10187/week @ 2021-09-16 11131/week @ 2021-09-23 9923/week @ 2021-09-30 13373/week @ 2021-10-07 11329/week @ 2021-10-14

41,237 downloads per month
Used in 105 crates (33 directly)

MIT license

225KB
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.

Crates.io Documentation Build Status

Quickstart

The loom documentation has significantly more documentation on how to use loom. But if you just want a jump-start, first add this to your Cargo.toml.

[target.'cfg(loom)'.dependencies]
loom = "0.5"

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));
    });
}

Then, run the test with

RUSTFLAGS="--cfg loom" cargo test --test buggy_concurrent_inc --release

Unsupported features

Loom currently does not implement the full C11 memory model. Here is the (incomplete) list of unsupported features.

  • SeqCst accesses (e.g. load, store, ..): They are are regarded as AcqRel. That is, they impose weaker synchronization, causing Loom to generate false alarms (not complete). See #180 for example. On the other hand, fence(SeqCst) is supported.
  • Load buffering behavior: Loom does not explore some executions that are possible in the C11 memory model. That is, there can be a bug in the checked code even if Loom says there is no bug (not sound). See the load_buffering test case in tests/litmus.rs.

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

~1.8–2.6MB
~46K SLoC