Volatile

@Target(allowedTargets = [AnnotationTarget.FIELD])
expect annotation class Volatile(source)

Marks the backing field of the annotated var property as volatile, meaning that reads and writes to this field are atomic and writes are always made visible to other threads. If another thread reads the value of this field (e.g. through its accessor), it sees not only that value, but all side effects that led to writing that value.

This annotation has effect in Kotlin/JVM and Kotlin/Native.

Note that only backing field operations are atomic when the field is annotated with Volatile. For example, if the property getter or setter make several operations with the backing field, a property operation, i.e. reading or setting it through these accessors, is not guaranteed to be atomic.

Since Kotlin

1.9
actual typealias Volatile = kotlin.jvm.Volatile(source)

Marks the JVM backing field of the annotated var property as volatile, meaning that reads and writes to this field are atomic and writes are always made visible to other threads. If another thread reads the value of this field (e.g. through its accessor), it sees not only that value, but all side effects that led to writing that value.

Note that only backing field operations are atomic when the field is annotated with Volatile. For example, if the property getter or setter make several operations with the backing field, a property operation, i.e. reading or setting it through these accessors, is not guaranteed to be atomic.

Since Kotlin

1.9
@Target(allowedTargets = [AnnotationTarget.FIELD])
actual annotation class Volatile(source)

Marks the backing field of the annotated var property as volatile, meaning that reads and writes to this field are atomic and writes are always made visible to other threads. If another thread reads the value of this field (e.g. through its accessor), it sees not only that value, but all side effects that led to writing that value.

Note that only backing field operations are atomic when the field is annotated with Volatile. For example, if the property getter or setter make several operations with the backing field, a property operation, i.e. reading or setting it through these accessors, is not guaranteed to be atomic.

Since Kotlin

1.9