#atomic #lock-free

loom

Permutation testing for concurrent code

29 releases

0.5.0 Apr 12, 2021
0.4.0 Dec 3, 2020
0.3.6 Oct 8, 2020
0.3.5 Jul 26, 2020
0.0.1 Dec 7, 2018

#14 in Concurrency

Download history 15736/week @ 2021-01-15 13487/week @ 2021-01-22 13403/week @ 2021-01-29 9837/week @ 2021-02-05 10390/week @ 2021-02-12 39983/week @ 2021-02-19 18527/week @ 2021-02-26 14177/week @ 2021-03-05 12273/week @ 2021-03-12 12487/week @ 2021-03-19 11957/week @ 2021-03-26 9920/week @ 2021-04-02 9878/week @ 2021-04-09 8342/week @ 2021-04-16 8339/week @ 2021-04-23 6921/week @ 2021-04-30

64,265 downloads per month
Used in 38 crates (25 directly)

MIT license

215KB
4.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

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–620KB
~13K SLoC