tokio-rs / loom

Concurrency permutation testing tool for Rust.
MIT License
2.09k stars 110 forks source link

Non-threaded store causes less iterations #168

Open Mark-Simulacrum opened 4 years ago

Mark-Simulacrum commented 4 years ago

The following two test cases on loom 0.3.5 iterate 4 (test_load) and 3 (test_load_with_initial_store) times, even though I expected both to have the same behavior.

#![cfg(test)]

use loom::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering::SeqCst;
use std::sync::Arc;

#[test]
fn test_load() {
    loom::model(move || {
        let v1 = Arc::new(AtomicUsize::new(0));
        let v2 = v1.clone();

        loom::thread::spawn(move || {
            v1.store(1, SeqCst);
        });

        v2.load(SeqCst);
    });
}

#[test]
fn test_load_with_initial_store() {
    loom::model(move || {
        let v1 = Arc::new(AtomicUsize::new(0));
        v1.store(0, SeqCst);
        let v2 = v1.clone();

        loom::thread::spawn(move || {
            v1.store(1, SeqCst);
        });

        v2.load(SeqCst);
    });
}