read/write volatile
read/write volatile
Posted Jan 10, 2026 9:33 UTC (Sat) by plugwash (subscriber, #29694)In reply to: read/write volatile by josh
Parent article: READ_ONCE(), WRITE_ONCE(), but not for Rust
The situation is a little more subtle than that.
Relaxed atomics on a given memory location, must behave as-if they had a well-defined order (though this order may differ from operations on other memory locations, unless fences are used), and this must apply to the whole set of atomic operations. You may only be using load and store on a particular location, but the compiler doesn't know that. Other code might be performing other atomic operations on that location.
My understanding is that this effectively means that if you implement read-modify-write operations by using a global lock, you must also implement plain write operations using that same global lock.
