std-function
compiler_fence: compiler-only ordering
A compiler fence constrains compiler transformations and can participate in specialized same-thread asynchronous-context synchronization. It is not a substitute for an inter-thread hardware fence. This ordinary single-thread example illustrates the API only, not a signal-handler protocol. Expected stdout (not executed): 1 Common mistake: Replacing an inter-thread fence with compiler_fence.
Formal Syntax & Structure
rust syntaxrust
std::sync::atomic::compiler_fence(order: Ordering)Working Example
Example Snippetrust
fn main() { use std::sync::atomic::{AtomicUsize, Ordering::*, compiler_fence}; let n = AtomicUsize::new(1); compiler_fence(SeqCst); println!("{}", n.load(Relaxed));}