AtomicReference

An AtomicReference uses CAS instruction to get and update the wrapped volatile variable to ensure lock free thread safety.

Examples

val person = AtomicReference(toImmutable(Person()))
val newPerson = toImmutable(Person())
val value = person.value
person.compareAndSet(value, newPerson)

class AtomicReference<T>(value: T)
typealias AtomicReference = <ERROR CLASS><T>

Constructors

AtomicReference
Link copied to clipboard
common
fun <T> AtomicReference(value: T)

Functions

compareAndSet
Link copied to clipboard
common

Compares the current value to expected and if it matches, replaces with new value. If the result is successful, it returns true, otherwise false. The get and update operations are performed atomically. The new value must be an immutable object. Use toImmutable to make an immutable version of an object.

fun compareAndSet(expected: T, new: T): Boolean
equals
Link copied to clipboard
common
open operator override fun equals(other: Any?): Boolean
hashCode
Link copied to clipboard
common
open override fun hashCode(): Int
toString
Link copied to clipboard
common
open override fun toString(): String

Properties

value
Link copied to clipboard
common

The wrapped value

var value: T