Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardKotlinJVM memory model happens-beforeSingle-choice MCQ

Two threads each execute `r1 = x; y = 1` and `r2 = y; x = 1` respectively, where x and y start at 0 and are plain (non-volatile) fields. Under the JVM Memory Model, is the outcome r1 == 1 && r2 == 1 possible?

// shared: var x = 0; var y = 0 (plain, non-volatile) // Thread 1 r1 = x y = 1 // Thread 2 r2 = y x = 1 // Question: can we end with r1 == 1 && r2 == 1 ?