compareAndSet
Atomically stores the given new value into this AtomicBoolean if the current value equals the expected value, returns true if the operation was successful and false only if the current value was not equal to the expected value.
This operation has so-called strong semantics, meaning that it returns false if and only if current and expected values are not equal.
Comparison of values is done by value.
Since Kotlin
2.1Samples
import kotlin.concurrent.atomics.*
import kotlin.concurrent.thread
fun main() {
//sampleStart
val a = AtomicBoolean(true)
// Current value true is equal to the expected value true -> compareAndSet succeeds.
println(a.compareAndSet(true, false)) // true
println(a.load()) // false
// Current value false is not equal to the expected value true -> compareAndSet fails.
println(a.compareAndSet(true, false)) // false
println(a.load()) // false
//sampleEnd
}
Atomically stores the given new value into this AtomicBoolean if the current value equals the expected value, returns true if the operation was successful and false only if the current value was not equal to the expected value.
Comparison of values is done by value.
Since Kotlin
2.1Atomically stores the given new value into this AtomicBoolean if the current value equals the expected value, returns true if the operation was successful and false only if the current value was not equal to the expected value.
Comparison of values is done by value.
Has the same memory effects as java.util.concurrent.atomic.AtomicBoolean.compareAndSet.
Since Kotlin
2.1Atomically stores the given new value into this AtomicBoolean if the current value equals the expected value, returns true if the operation was successful and false only if the current value was not equal to the expected value.
This operation has so-called strong semantics, meaning that it returns false if and only if current and expected values are not equal.
Comparison of values is done by value.
Since Kotlin
2.1Atomically stores the given new value into this AtomicBoolean if the current value equals the expected value, returns true if the operation was successful and false only if the current value was not equal to the expected value.
Comparison of values is done by value.
Since Kotlin
2.1Atomically stores the given new value into this AtomicBoolean if the current value equals the expected value, returns true if the operation was successful and false only if the current value was not equal to the expected value.
Comparison of values is done by value.