compareAndExchange

fun compareAndExchange(expected: Int, newValue: Int): Int(source)

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

Provides sequential consistent ordering guarantees and cannot fail spuriously.

Since Kotlin

1.9