compareExchange

fun <T : Comparable<T>> compareExchange(typedArray: TypedArray<*, *, *, T>, index: Int, expectedValue: T, replacementValue: T): T(source)

Replaces the value at the given position in the array if the original value equals the given expected value, returning the original value. Until this atomic operation completes, any other read or write operation against the array will block.