{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreiclayrb2if47d5mu5fuwwdxdfljrg5xu3jxk6dm767a3bxhmfxmgq",
"uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mmovaqrbn672"
},
"path": "/t/include-racy-reads-in-rust-memory-model-with-maybeinvalid-t/24289?page=2#post_27",
"publishedAt": "2026-05-25T15:06:16.000Z",
"site": "https://internals.rust-lang.org",
"textContent": "The idea is that you read into a `MaybeUninit` (using a special command designed to do possibly racy reads, that contains any necessary synchronization) and only `assume_init` it once you determine that the read is unraced.\n\nDoing this is technically UB according to C11, but nothing seems to actually rely on the UB (the proofs about the memory model don't rely on it and the compiler doesn't exploit it either), so it would be possible to define Rust to make it not UB without needing any actual changes to anything other than documentation. This thread is, from my point of view, discussing whether it should continue to be UB or whether we should change the rules.\n\nStoring the value as initialised (rather than `MaybeUninit`) without checking to see if the read has been raced on would be UB even under the current compiler, pretty much for the reasons you mention.",
"title": "Include racy reads in Rust memory model with `MaybeInvalid<T>`"
}