addAndFetch
Atomically adds the given value to the current value of this AtomicInt and returns the new value.
Since Kotlin
2.1Samples
import kotlin.concurrent.atomics.*
import kotlin.concurrent.thread
fun main() {
//sampleStart
val a = AtomicInt(7)
// Returns the new value after the addition.
println(a.addAndFetch(10)) // 17
println(a.load()) // 17
//sampleEnd
}
Atomically adds the given value to the current value of this AtomicInt and returns the new value.
Since Kotlin
2.1Atomically adds the given value to the current value of this AtomicInt and returns the new value.
Has the same memory effects as java.util.concurrent.atomic.AtomicInteger.addAndGet.
Since Kotlin
2.1Atomically adds the given value to the current value of this AtomicInt and returns the new value.
Since Kotlin
2.1Atomically adds the given value to the current value of this AtomicInt and returns the new value.
Since Kotlin
2.1Atomically adds the given value to the current value of this AtomicInt and returns the new value.