Make SafePublicationLazyImpl.initializer volatile
This establishes happens-before relation between nulling out the initializer and checking whether it is null. This will prevent the subsequent _value reads being reordered before the initializer reads. #KT-21868 Fixed
This commit is contained in:
@@ -174,7 +174,7 @@ private class InitializedLazyImpl<out T>(override val value: T) : Lazy<T>, Seria
|
||||
|
||||
@kotlin.jvm.JvmVersion
|
||||
private class SafePublicationLazyImpl<out T>(initializer: () -> T) : Lazy<T>, Serializable {
|
||||
private var initializer: (() -> T)? = initializer
|
||||
@Volatile private var initializer: (() -> T)? = initializer
|
||||
@Volatile private var _value: Any? = UNINITIALIZED_VALUE
|
||||
// this final field is required to enable safe publication of constructed instance
|
||||
private val final: Any = UNINITIALIZED_VALUE
|
||||
|
||||
Reference in New Issue
Block a user