Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardJavaJMM happens-beforeSingle-choice MCQ

Two threads share a plain int field x (initially 0). Thread A executes 'x = 1; r1 = y;' and Thread B executes 'y = 1; r2 = x;' where y is also a plain field. Under the Java Memory Model, what guarantees the outcome (r1 == 0 && r2 == 0)?

// shared: int x = 0, y = 0; // Thread A: // Thread B: x = 1; y = 1; r1 = y; r2 = x;