How to share code with Android(Kotlin/JVM) and iOS...
# kotlin-native
l
How to share code with Android(Kotlin/JVM) and iOS(Kotlin/Native), since they have difference concurrency model. In the [officeial guide](https://kotlinlang.org/docs/tutorials/native/mpp-ios-android.html) and [Kotlin conf](https://github.com/JetBrains/kotlinconf-app), we can see in the commonMain sourcesets one can’t use Kotlin/Naive function to freeze an object to create a
DetachedObjectGraph
nor to use
Worker
. What if the commonMain have concurreny logic and I want to share those with Android and iOS?
The kotlinconf project shows using coroutine to achieve async request (while not really multi threaded). And coroutine is planing to support real multi thread in Kotlin/Native. So, is it true that in the near future we can use coroutine to achieve concurrency while keep code common (ie. compiles) to both Android and iOS (even more targets)
g
Yes, multi-threaded coroutines for K/N are planned https://github.com/Kotlin/kotlinx.coroutines/issues/462
l
Thanks. One more thing to make sure is that under coroutine model, we can have shared variable between different coroutines so they are also possibly shared between threads. Should we take care of synchronization(and how), because in K/N we will get an IncorrectDereferenceException.