Volatile

Common
JS
1.0
@Target([AnnotationTarget.FIELD]) @DeprecatedSinceKotlin("1.9") annotation class Volatile
(Common source) (JS source)
Deprecated: Use kotlin.concurrent.Volatile annotation in multiplatform code instead.
JVM
1.0
@Target([AnnotationTarget.FIELD]) annotation class Volatile
(source)
For JVM

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.

For Common

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.

This annotation has effect only in Kotlin/JVM. It's recommended to use kotlin.concurrent.Volatile annotation instead in multiplatform projects.

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.

Constructors

Common
JVM
JS
1.0

<init>

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.

<init>()

Extension Properties

JVM
1.0

annotationClass

Returns a KClass instance corresponding to the annotation type of this annotation.

val <T : Annotation> T.annotationClass: KClass<out T>