expression

AcqRel ordering for read-modify-write

AcqRel combines acquire behavior for the read portion and release behavior for the write portion. On a failed comparison there is no write, and the separately specified failure ordering governs the load. Expected stdout (not executed): 1 2 Common mistake: Passing AcqRel to a pure load.

Formal Syntax & Structure

rust syntaxrust
n.swap(value, Ordering::AcqRel)

Working Example

Example Snippetrust
fn main() {    use std::sync::atomic::{AtomicUsize, Ordering::*};    let state = AtomicUsize::new(1);    let prev = state.swap(2, AcqRel);    println!("{} {}", prev, state.load(Acquire));}
Rust Reference