compareAndSet

Native
1.3
fun compareAndSet(
    index: Int,
    expectedValue: Long,
    newValue: Long
): Boolean

(source)

Atomically sets the value of the element at the given index to the new value if the current value equals the expected value. Returns true if the operation was successful and false only if the current value of the element was not equal to the expected value.

Provides sequential consistent ordering guarantees and never fails spuriously.

Exceptions

IndexOutOfBoundsException - if the index is out of bounds of this array.