3 ms·
Rust provides volatile load and store intrinsics which do exactly what they say on the box, but given you talk about "concurrency stuff" I expect they're comple
by tialaramex 5y ago
Rust provides volatile load and store intrinsics which do exactly what they say on the box, but given you talk about "concurrency stuff" I expect they're completely irrelevant to you because this (older) meaning of volatile is about hardware memory access (e.g. for device drivers) and nothing to do with concurrency.
Java's "volatile" is sequential consistency on steroids, a promise that changes to a volatile variable "happen-before" anything else that thread does, and "happen-after" anything the thread already did. Rust's std::sync::atomic has a hardware fence which you could use to deliver this same outcome (throw away performance, gain sequential consistency).
For concurrency C++ volatile does not supply any semantics, except on MSVC. If you're looking at papers or reference implementations which assume C++ volatile has semantics that are relevant to concurrency you're probably looking at papers that only needed Acquire-release and it worked on the x86 CPU they tried it with, or they forgot to mention it only works on MSVC (which promises Acquire-release even on platforms other than x86).
- steveklabnik 5y ago> which do exactly what they say on the box I mean, the box says: https://doc.rust-lang.org/stable/std/ptr/fn.read_volatile.html#notes https://doc.rust-lang.org/stable/std/ptr/fn.read_volatile.ht... > Rust does not currently have a rigorously and formally defined memory model, so the precise semantics of what “volatile” means here is subject to change over time. That being said, the semantics will almost always end up pretty similar to C11’s definition of volatile. Which isn't exactly "exact", you know?
- tialaramex 5y agoIt's not. But I feel confident (perhaps my confidence is misplaced) that this is because what's really going on here is that this does what LLVM does, and there's some risk LLVM changes exactly what it does, most likely to suit clang so in that case Rust has to go along for the ride or perhaps get itself a new suite of compiler backends... If so I feel that risk is small and continues to shrink.
- steveklabnik 5y agoTotally. Hence my original question, some folks want an actual airtight guarantee, some are comfy with where things are now.