I assume Rust concurrency guarantees will prevent races and have this covered. Except of course if you use unsafe. Right?
It is actually fairly tricky to get a value across threads like this. The simplest I could come up with is this:
struct UnsafeSync(T);
unsafe impl Sync for UnsafeSync {}
fn main() {
let i = std::sync::Arc::new(UnsafeSync(std::cell::Cell::new(0)));
let thread_i = i.clone();
std::thread::spawn(move || {
thread_i.0.set(1);
});
eprintln!("i is {}", i.0.get());
}
https://play.rust-lang.org/?version=stable&mode=debug&editio...