compareAndExchange

expect fun compareAndExchange(expectedValue: Boolean, newValue: Boolean): Boolean(source)

Atomically stores the given new value into this AtomicBoolean if the current value equals the expected value and returns the old value in any case.

Comparison of values is done by value.

Since Kotlin

2.1

Samples

actual fun compareAndExchange(expectedValue: Boolean, newValue: Boolean): Boolean(source)

Atomically stores the given new value into this AtomicBoolean if the current value equals the expected value and returns the old value in any case.

Comparison of values is done by value.

Since Kotlin

2.1
actual fun compareAndExchange(expectedValue: Boolean, newValue: Boolean): Boolean(source)

Atomically stores the given new value into this AtomicBoolean if the current value equals the expected value and returns the old value in any case.

Comparison of values is done by value.

In order to maintain compatibility with Java 8, compareAndExchange is implemented using java.util.concurrent.atomic.AtomicBoolean.compareAndSet, since java.util.concurrent.atomic.AtomicBoolean.compareAndExchange method is only available starting from Java 9.

In the future releases it's planned to delegate the implementation of compareAndExchange to java.util.concurrent.atomic.AtomicBoolean.compareAndExchange for users running JDK 9 or higher.

Since Kotlin

2.1
actual fun compareAndExchange(expectedValue: Boolean, newValue: Boolean): Boolean(source)

Atomically stores the given new value into this AtomicBoolean if the current value equals the expected value and returns the old value in any case.

Comparison of values is done by value.

Since Kotlin

2.1
actual fun compareAndExchange(expectedValue: Boolean, newValue: Boolean): Boolean(source)

Atomically stores the given new value into this AtomicBoolean if the current value equals the expected value and returns the old value in any case.

Comparison of values is done by value.

Since Kotlin

2.1
actual fun compareAndExchange(expectedValue: Boolean, newValue: Boolean): Boolean(source)

Atomically stores the given new value into this AtomicBoolean if the current value equals the expected value and returns the old value in any case.

Comparison of values is done by value.

Since Kotlin

2.1