Hello I'm trying to use an <AtomicInteger> to writ...
# getting-started
i
Hello I'm trying to use an AtomicInteger to write a multiplatform library But it seems to be deprecated on version 1.9 My question: 1. Is it better to downgrade the kotlin version I'm using? If yes, what version is recommended for writing a multiplatform library? 2. How do we implement an Atomic field/variable in kotlin 1.9? it seems I cannot find
kotlin.concurrent.AtomicInt
as suggested in the page Thank you in advance!
also consider https://github.com/Kotlin/kotlinx-atomicfu for multiplatform
a
you can also try arrow-atomic if you want to go multiplatform but don't want to use atomicfu https://arrow-kt.io/learn/coroutines/concurrency-primitives/#atomic
i
@ephemient oh gosh, I'm embarassed that I missed the
native
part was missing from the dependency, I thought they were the same also, thanks for the suggestion of using atomicfu, will see on that thanks!
@ephemient weirdly, the
AtomicInt
doesn't exist under the
concurrent
of my
kotlin-stdlib-common-1.9.0
, neither does the
Atomics.kt
file
e
see the docs. they are native-only
same as the older class with
native
in its package name
if you want something to use on other platforms, you need one of the other alternatives mentioned here
(or just build it yourself; Java has its own atomics, Kotlin provides them on native, and JS isn't threaded so it doesn't need any)
👍 1
i
oh I see, so it wont be usable on multiplatform right? my bad, I wasn't really familiar with kotlin multiplatform yet
e
stdlib docs has this badge
i
hmm I'm not sure I get it by that logic, the tags means I should be able to use them on multiplatform, right? (since the badge includes JVM, JS and Native) So why can't I import it?
sorry if its a very noob question
e
image.png
compare
i
ah, sooo the AtomicInt class itself is
native
but the
kotlin-stdlib / kotlin.concurrent
is not? sorry, I came from golang and all this is a bit confusing for me
e
yes
i
got it, thanks man