exchange

expect fun exchange(newValue: T): T(source)

Atomically stores the given new value into this AtomicReference. and returns the old value.

Since Kotlin

2.1

Samples

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
}
actual fun exchange(newValue: T): T(source)

Atomically stores the given new value into this AtomicReference and returns the old value.

Since Kotlin

2.1
actual fun exchange(newValue: T): T(source)

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.1
actual fun exchange(newValue: T): T(source)

Atomically stores the given new value into this AtomicReference and returns the old value.

Since Kotlin

2.1
actual fun exchange(newValue: T): T(source)

Atomically stores the given new value into this AtomicReference and returns the old value.

Since Kotlin

2.1
actual fun exchange(newValue: T): T(source)

Atomically stores the given new value into this AtomicReference and returns the old value.

Since Kotlin

2.1