-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AtomicRef<Int>.compareAndSet
always fails when value >= 128
on macOS and iOS
#369
Comments
AtomicRef<Int>.compareAndSet
fails when value >= 128
on macOS and iOS
AtomicRef<Int>.compareAndSet
fails when value >= 128
on macOS and iOSAtomicRef<Int>.compareAndSet
always fails when value >= 128
on macOS and iOS
This is the original issue: https://gitlab.com/trixnity/uniffi-kotlin-multiplatform-bindings/-/issues/24 |
Found that import kotlin.concurrent.AtomicReference
fun main() {
repeat(129) {
val a = AtomicReference(it)
val result = a.compareAndSet(it, 8192)
println("$it: $result")
}
} |
Is it an expected behavior and an imitation of JVM's Integer pooling? I also found that |
It seems like we need a proper inspection or compiler diagnostic here. So I'd say the behaviour is as intended, but we need a proper diagnostic to prevent such a bug (note: it's also reproducible with other primitives including booleans) |
Posted the solution internally, re-posting here:
|
I'm using kotlinx-atomicfu 0.22.0. I was having a problem where my program halts at
AtomicRef<Int>.getAndUpdate
, and I found thatAtomicRef<Int>.compareAndSet
always fails when the value >= 128 on macOS and iOS, both for JVM and native. For example:run result:
This does not happen when I use
AtomicInt
instead ofAtomicRef<Int>
.run result:
The text was updated successfully, but these errors were encountered: