Loading RustViz Engine...
Coordinate thread progress without OS mutexes using fetch_add and Ordering::Relaxed.
This problem is currently in blueprint template mode. Once the concept foundation is finalized, live in-browser WebAssembly compilation and test assertion runners will be enabled here.
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
pub struct AtomicCounter {
val: Arc<AtomicUsize>,
}
impl AtomicCounter {
pub fn new() -> Self { Self { val: Arc::new(AtomicUsize::new(0)) } }
pub fn inc(&self) { self.val.fetch_add(1, Ordering::Relaxed); }
pub fn get(&self) -> usize { self.val.load(Ordering::Relaxed) }
}