Atomic
import arrow.atomic.AtomicInt
import arrow.atomic.update
import arrow.atomic.value
import arrow.fx.coroutines.parMap
suspend fun main() {
val count = AtomicInt(0)
(0 until 20_000).parMap {
count.update(Int::inc)
}
println(count.value)
}Atomic also offers some other interesting operators such as loop, update, tryUpdate, etc.
WARNING: Use AtomicInt and AtomicLong for Int and Long on Kotlin Native!
import arrow.atomic.AtomicInt
import arrow.atomic.update
import arrow.atomic.value
import arrow.fx.coroutines.parMap
suspend fun main() {
val count = AtomicInt(0)
(0 until 20_000).parMap {
count.update(Int::inc)
}
println(count.value)
}Atomic also offers some other interesting operators such as loop, update, tryUpdate, etc.
WARNING: Use AtomicInt and AtomicLong for Int and Long on Kotlin Native!
import arrow.atomic.AtomicInt
import arrow.atomic.update
import arrow.atomic.value
import arrow.fx.coroutines.parMap
suspend fun main() {
val count = AtomicInt(0)
(0 until 20_000).parMap {
count.update(Int::inc)
}
println(count.value)
}Atomic also offers some other interesting operators such as loop, update, tryUpdate, etc.
WARNING: Use AtomicInt and AtomicLong for Int and Long on Kotlin Native!
Constructors
Functions
Compare current value with expected and set to new if they're the same. Note, 'compare' is checking the actual object id, not 'equals'.
Compare current value with expected and set to new if they're the same. Note, 'compare' is checking the actual object id, not 'equals'.