compareAndSet
Atomically stores the given new value into this AtomicLong 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 = AtomicLong(7)
// Current value 7 is equal to the expected value 7 -> compareAndSet succeeds.
println(a.compareAndSet(7, 10)) // true
println(a.load()) // 10
// Current value 10 is not equal to the expected value 2 -> compareAndSet fails.
println(a.compareAndSet(2, 12)) // false
println(a.load()) // 10
//sampleEnd
}
Atomically stores the given new value into this AtomicLong. 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 AtomicLong 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.AtomicLong.compareAndSet.
Since Kotlin
2.1Atomically stores the given new value into this AtomicLong 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 AtomicLong 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 AtomicLong 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.