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

Without any synchronization, a thread reads this lazily-initialized field twice. The JMM permits a surprising outcome. Which one?

class Holder { var ref: Node? = null // plain, non-volatile } // Thread A: holder.ref = Node(42) // Thread B reads holder.ref twice: val first = holder.ref val second = holder.ref // suppose first != null