Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardKotlinVolatile and atomics on JVMSingle-choice MCQ

Consider a `@Volatile var flag = false` and a non-volatile `var data = 0`, with one thread writing `data = 42; flag = true` and another doing `if (flag) print(data)`. Which JMM property makes the reader guaranteed to see `data == 42`, and what would break it?

// Writer thread: data = 42 flag = true // Reader thread: if (flag) println(data)