Hi. I’m updating an Android/iOS multiplatform proj...
# kotlin-native
m
Hi. I’m updating an Android/iOS multiplatform project to 1.4, but I’m having a hard time understanding the changes in coroutines and concurrency. Running a code like this:
Copy code
val scope = CoroutineScope(Dispatchers.Main + SupervisorJob())
...
scope.launch {
	val something = withContext(Dispatchers.Default) { suspendCall() }
	println(something)
}
Works fine in Andorid but in iOS I get:
Uncaught Kotlin exception: kotlin.native.IncorrectDereferenceException: illegal attempt to access non-shared <object>@3faca88 from other thread
As far as I know
withContext(Dispatchers.Default) { suspendCall() }
should complete the call in the Default dispatcher and then the usages inside of the Man scope should not be a problem. Any clues 😓?
k
Do you have more code? This generally happens if you have an object in native code from Kotlin, then attempt to access it in another thread without freezing it.
m
Thanks for your answer @kpgalligan and sorry for my late reply. Yes, I realized that my problem was that the suspendCall in my real code was a use-case passed to my presenter as a dependency. As the object is created in a different thread than the one that is executing it, then I got the error
I understood better the reason after read this blog entry: https://blog.jetbrains.com/kotlin/2020/07/kotlin-native-memory-management-roadmap/