Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardC#volatile and memory barriersSingle-choice MCQ

On a weakly-ordered CPU (e.g. ARM64), two threads run the methods below with x and y initially 0. Under the ECMA-335 / .NET memory model, which outcome is the one that volatile semantics are specifically designed to FORBID?

// shared: int x = 0, y = 0; // Thread A: x = 1; // plain store Volatile.Write(ref y, 1); // Thread B: int ry = Volatile.Read(ref y); int rx = x; // plain load // observe (ry, rx)