use interweave::{World, explore};
const VALUE: i32 = 42;
const READY: i32 = 1;
fn publish(world: &mut World) {
let data = world.atomic("data", 0);
let ready = world.atomic("ready", 0);
let (data_w, ready_w) = (data.clone(), ready.clone());
world.spawn("producer", async move {
ready_w.store(READY).await; data_w.store(VALUE).await; Ok(())
});
world.spawn("consumer", async move {
if ready.load().await == READY {
let v = data.load().await;
if v != VALUE {
return Err(format!("read the value before it was published: {v}").into());
}
}
Ok(())
});
}
fn main() {
match explore(&publish, &mut ()) {
Ok(()) => println!("no interleaving reads stale data (unexpected for this program)"),
Err(failed) => {
println!("found a schedule that reads the value before it was published:");
println!(" {failed}");
}
}
}