exchange
Atomically stores the given new value into this AtomicReference. and returns the old value.
Since Kotlin
2.1Samples
import kotlin.concurrent.atomics.*
import kotlin.concurrent.thread
fun main() {
//sampleStart
val a = AtomicReference("aaa")
println(a.exchange("bbb")) // aaa
println(a.load()) // bbb
//sampleEnd
}
Atomically stores the given new value into this AtomicReference and returns the old value.
Since Kotlin
2.1Samples
import kotlin.concurrent.atomics.*
import kotlin.concurrent.thread
fun main() {
//sampleStart
val a = AtomicReference("aaa")
println(a.exchange("bbb")) // aaa
println(a.load()) // bbb
//sampleEnd
}
Atomically stores the given new value into this AtomicReference and returns the old value.
Has the same memory effects as java.util.concurrent.atomic.AtomicReference.getAndSet.
Since Kotlin
2.1Samples
import kotlin.concurrent.atomics.*
import kotlin.concurrent.thread
fun main() {
//sampleStart
val a = AtomicReference("aaa")
println(a.exchange("bbb")) // aaa
println(a.load()) // bbb
//sampleEnd
}
Atomically stores the given new value into this AtomicReference and returns the old value.
Since Kotlin
2.1Samples
import kotlin.concurrent.atomics.*
import kotlin.concurrent.thread
fun main() {
//sampleStart
val a = AtomicReference("aaa")
println(a.exchange("bbb")) // aaa
println(a.load()) // bbb
//sampleEnd
}
Atomically stores the given new value into this AtomicReference and returns the old value.
Since Kotlin
2.1Samples
import kotlin.concurrent.atomics.*
import kotlin.concurrent.thread
fun main() {
//sampleStart
val a = AtomicReference("aaa")
println(a.exchange("bbb")) // aaa
println(a.load()) // bbb
//sampleEnd
}
Atomically stores the given new value into this AtomicReference and returns the old value.
Since Kotlin
2.1Samples
import kotlin.concurrent.atomics.*
import kotlin.concurrent.thread
fun main() {
//sampleStart
val a = AtomicReference("aaa")
println(a.exchange("bbb")) // aaa
println(a.load()) // bbb
//sampleEnd
}