expression

False sharing: independent values on a shared cache line

False sharing can increase coherence traffic even when workers update different variables. Rust field placement, CPU cache organization and workload determine the effect. This sample checks only two independent values, not their layout or performance. Expected stdout (not executed): 3 5 Common mistake: Assuming independent atomic variables always have independent cache costs.

Formal Syntax & Structure

rust syntaxrust
independent frequently written values may share a cache line

Working Example

Example Snippetrust
fn main() {    use std::sync::atomic::{AtomicUsize, Ordering::Relaxed};    let counts = [AtomicUsize::new(0), AtomicUsize::new(0)];    std::thread::scope(|s| {        s.spawn(|| { counts[0].fetch_add(3, Relaxed); });        s.spawn(|| { counts[1].fetch_add(5, Relaxed); });    });    println!("{} {}", counts[0].load(Relaxed), counts[1].load(Relaxed));}
Rust Reference