rust-lang/rust — pull request #19835 by pythonesque (2014-12-14 09:57:25+00:00)
Title: Add LLVM's unordered intrinsic to Rust.

This corresponds to the JMM memory model's non-volatile reads and writes to shared variables. It provides fairly weak guarantees, but prevents UB (specifically, you will never see a value that was not written _at some point_ to the provided location). It is not part of the C++ memory model and is only legal to provide to LLVM for loads and stores (not fences, atomicrmw, etc.).

For an example of a valid use of this ordering, consider a "cached" bit that is initially unset. If the cached bit is set, there is no need to perform an expensive calculation, while if it is not you perform the calculation and then set the bit. Because the bit is never unset (only set) and seeing the bit set out of order doesn't matter (seeing it unset after it was set just means you do extra work, and it will never be unset), this usage is valid.

Because it is new to Rust and it provides so few guarantees, for now only the intrinsic is provided--this patch doesn't add it to any of the higher-level atomic wrappers.