expression

Release/acquire: conditional publication

A reader that observes the releasing write through an acquire load can rely on operations sequenced before the release. A false observation does not establish that relationship. This example allows either initial observation, and checks the value only if publication is observed. Expected stdout (not executed): 42 Common mistake: Assuming any acquire load synchronizes with an arbitrary release store.

Formal Syntax & Structure

rust syntaxrust
flag.store(true, Release); flag.load(Acquire)

Working Example

Example Snippetrust
fn main() {    use std::{sync::atomic::{AtomicBool, AtomicUsize, Ordering::*}, thread};    let ready = AtomicBool::new(false);    let data = AtomicUsize::new(0);    thread::scope(|s| {        s.spawn(|| { data.store(42, Relaxed); ready.store(true, Release); });        if ready.load(Acquire) { assert_eq!(data.load(Relaxed), 42); }    });    println!("{}", data.load(Relaxed));}
Rust Reference