External Publication
Visit Post

Include racy reads in Rust memory model with `MaybeInvalid<T>`

Rust Internals [Unofficial] June 1, 2026
Source

Oh sorry, I missed the RwLock. That has a different size than T so this doesn't literally work, but I guess we could imagine that the RwLock state is stored out-of-band.

The return T::default() is wrong though since the asm code may return a different value.

And generally that story is pretty far from what the asm actually does so arguing that the asm is a refinement of this code is far from trivial. For instance, the story code performs a bunch of synchronization (the try_read internally does an "acquire"), while the asm code doesn't do the same synchronization -- but for the story to be valid the asm code has to perform at least as much synchronization as the story.

Discussion in the ATmosphere

Loading comments...