rust-lang / nomicon

The Dark Arts of Advanced and Unsafe Rust Programming
https://doc.rust-lang.org/nomicon/
Apache License 2.0
1.74k stars 256 forks source link

Incorrect Statement about What is Impossible #449

Open pl170491 opened 2 months ago

pl170491 commented 2 months ago

In the chapter about Atomics (Chapter 8.3 sub-section "Data Accesses") there is a very strong statement made about the possibility of synchronizing data between any two or more threads using only normal (i.e. non-atomic) data accesses. I believe there exists an algorithm for sharing data between two threads deterministically and correctly without the use of any atomic operations, and it works even on weakly ordered hardware (or at least so far I've tested it on Apple M3 which is ARM based, as well as the more strongly ordered Intel x86/64). As such, assuming I'm not utterly mistaken, I'd like to request that this statement be altered to better describe reality:

"It is literally impossible to write correct synchronized code using only data accesses."

The code is located here if you're interested in testing it to prove to yourself that what I say is true on your personal hardware. https://github.com/alareti/fallout