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