Why loom is happy with this?

2026-11-05来源 Rust Users ForumEnglish
 use loom::sync::Arc; use loom::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; loom::model(|| { let ptr = Box::into_raw(Box::new(0)); let flag = Arc::new(AtomicBool::new(false)); let flag2 = flag.clone(); loom::thread::spawn(move || { unsafe { *ptr = 1 }; flag.store(true, Ordering::Relaxed); }); loom::thread::spawn(move || { if flag2.load(Ordering::Relaxed) { assert!(unsafe { *ptr == 1 }); } }); }); 

this passes, could someone please explain why? thanks!
edit: oh, UB?

3 posts - 3 participants

Read full topic

原文:https://www.a8q9.cn/en/article/why-loom-is-happy-with-this-f823a5.html

相关文章