{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreies4xnvle5eeg3zjagf73zvrcbeqmlumjomo33cxm7mqehkjc2hd4",
    "uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mloa6zchrx32"
  },
  "path": "/t/include-racy-reads-in-rust-memory-model-with-maybeinvalid-t/24289#post_7",
  "publishedAt": "2026-05-12T13:52:26.000Z",
  "site": "https://internals.rust-lang.org",
  "tags": [
    "can be done"
  ],
  "textContent": "ais523:\n\n> I've thought quite a lot about this, and I'm pretty sure that the correct model is along the lines of \"a data race for which the value read affects observable program behaviour is undefined behaviour\"\n\nYes that's exactly what this thread is about: racy reads return `undef`. `undef` is a value where if the program behavior ever depends on what the value is, that's UB. (`poison` would work just as well for us here.)\n\nHowever it's very hard to actually make _both_ reads in my example return `undef`. One of the reads has to happen first, before any write even occurred, at which point it can only return 0 (the initial value of `X` and `Y`). Only later do we realize that actually there's a write that races with this read, now we have to... go back in time and change what the read returned? That's not even a meaningful thing to say.  In the current semantics, we can just say \"UB\" at this point and we're fine. But in a world where data-races are not always UB, we need an odd form of time-traveling semantics. That can be done, but it is exceedingly complicated and nobody has managed to actually work with such a model so far.\n\nYou can also entirely forget about having a tool like Miri for such a semantics. So we can add that to the list of downsides of this model. (Miri of course already has the same problem for the variant of this program where the two loads are `Ordering::Relaxed`. But given that only a tiny fraction of reads in any given program use that ordering, I think it is a very different situation if we have that problem for _all_ reads vs. only for a few of them.) Miri would become largely useless for finding data races if we adopted this model.",
  "title": "Include racy reads in Rust memory model with `MaybeInvalid<T>`"
}