compareAndExchange

fun compareAndExchange(index: Int, expectedValue: T, newValue: T): T(source)

Atomically sets the value of the element at the given index to the new value if the current value equals the expected value and returns the old value of the element in any case.

Provides sequential consistent ordering guarantees and never fails spuriously.

Since Kotlin

1.9

Throws

if the index is out of bounds of this array.