Hey all, I’m running into some issues with object ...
# kotlin-native
l
Hey all, I’m running into some issues with object concurrency using Kotin Native 1.3.61. I’m creating an instance of the following class in the UI thread and then calling it’s properties/members from “_DispatchQueue.global(qos: .background).async_” on iOS. It’s throwing kotlin.native.IncorrectDereferenceException even though I’m attributing my variables with @SharedImmutable. Any ideas?
Copy code
class ThreadSafetyTest {

    @SharedImmutable
    val mapper: (value: String) -> String = { value: String ->
        "Mapped: $value"
    }

    @SharedImmutable
    val mapper2 = "Mapper 2"

}
k
@SharedImmutable does not work in that way
d
I'm fairly certain
@SharedImmutable
doesn't work on member.s
What he said. 😅
k
i am surprised it's not giving you an error
l
Hmmm…
k
you need to freeze the object
l
So what does it work on then?
k
globals
☝🏼 1
l
Funny that. The freeze() method is unavailable for some reason.
d
Are you in common code?
k
yeah it's a native API, but easy to create expect/actuals for
l
commonMain
k
i'm not sure why JB hasn't put the API in common
everyone targeting native ends up doing it for the most part
l
Ohh, so it IS available in say iosMain?
k
yes
l
💣
Awesome… Thanks!
FWIW guys… I think the reason freeze() is not available in common is not all platforms have/need it. It looks like Android code for instance doesn’t have the method. I’m guessing the Kotlin Native code is compiled directly into Java bytecode much like it would be as if it was a part of the Android project code.
k
kotlin/native code is compiled to a native binary
and the fact that it's not used by all platforms doesn't mean it's not needed