Skip to content

Instantly share code, notes, and snippets.

@raphlinus
Last active November 5, 2023 16:35
Show Gist options
  • Save raphlinus/41d78d04d117ab0ba3b77065b9927966 to your computer and use it in GitHub Desktop.
Save raphlinus/41d78d04d117ab0ba3b77065b9927966 to your computer and use it in GitHub Desktop.
LB litmus test adapted to loom crate
use std::sync::atomic::Ordering;
use loom::{
sync::{atomic::AtomicU32, Arc},
thread,
};
#[test]
fn relaxed() {
loom::model(|| {
let x = Arc::new(AtomicU32::new(0));
let y = Arc::new(AtomicU32::new(0));
let th0 = {
let x = x.clone();
let y = y.clone();
thread::spawn(move || {
let r0 = x.load(Ordering::Relaxed);
y.store(1, Ordering::Relaxed);
r0
})
};
let th1 = thread::spawn(move || {
let r0 = y.load(Ordering::Relaxed);
x.store(1, Ordering::Relaxed);
r0
});
let th0_r0 = th0.join().unwrap();
let th1_r0 = th1.join().unwrap();
assert!(th0_r0 == 0 || th1_r0 == 0);
});
}
// Test that can be run in Vulkan memory model
// Place in alloy/tests subdir of
// https://github.com/KhronosGroup/Vulkan-MemoryModel
// then run "make" under alloy subdir
NEWWG
NEWSG
NEWTHREAD
ld.atom.scopedev.sc0 x = 1
st.atom.scopedev.sc0 y = 2
NEWWG
NEWSG
NEWTHREAD
ld.atom.scopedev.sc0 y = 2
st.atom.scopedev.sc0 x = 1
SOLUTION consistent[X]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment