3 ms·
> If it compiles, it is data-race free False: (0..10_000).into_par_iter().for_each(|_| { counter.store(counter.load(Ordering::SeqCst) + 1, Orderin
by bjourne 3y ago
> If it compiles, it is data-race free
False:
(0..10_000).into_par_iter().for_each(|_| {
counter.store(counter.load(Ordering::SeqCst) + 1, Ordering::SeqCst);
});
println!("counter {}", counter.load(Ordering::SeqCst));
Rustaceans who think the borrow checker is some kind of miracle cure against every type of bug there is gets under my skin.
- kam 3y agoA race condition is not the same as a data race, and nondeterminism is not the same as undefined behavior.
- bjourne 3y agoFine, but in practice a data race is just a special case of a race condition so my point still stands. Most multi-threaded code with races is more like my example than the author's and Rust will not magically prevent such race conditions.
- pjmlp 3y agoIndeed, I like your example, usually I go after external resources being accessed from same threads, database accesses without proper transaction management, or OS IPC, where the Rust threads don't have any visibility about what the other processes are doing.
- vacuity 3y agoAs a Rust user, the RESF-type no-effort comments are very frustrating. Hopefully it dies down in a few years.