Consider double-checked locking written in Kotlin. Why must `instance` be `@Volatile` for correctness under the JMM?
class Holder {
companion object {
@Volatile private var instance: Holder? = null
fun get(): Holder {
val local = instance
if (local != null) return local
return synchronized(this) {
instance ?: Holder().also { instance = it }
}
}
}
}