fetchAndDecrementAt
Atomically decrements the element of this AtomicIntArray at the given index by one and returns the old value of the element.
Since Kotlin
2.1Throws
if the index is out of bounds of this array.
Samples
import kotlin.concurrent.atomics.*
import kotlin.concurrent.atomics.AtomicArray
import kotlin.test.assertFailsWith
fun main() {
//sampleStart
val a = AtomicIntArray(intArrayOf(1, 2, 3))
println(a.fetchAndDecrementAt(1)) // 2
println(a.loadAt(1)) // 1
println(a.toString()) // [1, 1, 3]
//sampleEnd
}
Atomically decrements the element of this AtomicLongArray at the given index by one and returns the old value of the element.
Since Kotlin
2.1Throws
if the index is out of bounds of this array.
Samples
import kotlin.concurrent.atomics.*
import kotlin.concurrent.atomics.AtomicArray
import kotlin.test.assertFailsWith
fun main() {
//sampleStart
val a = AtomicLongArray(longArrayOf(1, 2, 3))
println(a.fetchAndDecrementAt(1)) // 2
println(a.loadAt(1)) // 1
println(a.toString()) // [1, 1, 3]
//sampleEnd
}