What does "Uncaught Kotlin exception: kotlin.Illeg...
# kotlin-native
f
What does "Uncaught Kotlin exception: kotlin.IllegalStateException: Illegal transfer state" in the context of using concurrency workers mean and how do I avoid it?
a
Objects transferred to workers should either have zero references or be frozen. Otherwise you will get this exception.
f
That's simply speaking not feasible. The objects don't work whilst frozen and the object structure is too complex to ensure zero references. Is there any way I can duplicate the object graph to give a worker it's own copy?
I'm going to write this off as impossible, since I'm starting with an existing app that uses a worker and simple work queue model there is simply speaking no way it can be mapped to the Kotlin native concurrency model, which probably raises a question on the Kotlin multiplatform stuff if there are simply speaking a lack of things to map concepts to.
a
Currently it is not possible to share unfrozen objects between threads. Unless you want to play with DetachedObjectGraph (which is like playing with fire). So basically your objects should be compatible with the K/N memory model. Which means they should be immutable or use Atomics + immutable data structures.
But there are good news, K/N team is working on improving the memory model. Eventually it should become possible to share mutable data.
f
So there is basically a conflict here between Kotlin multiplatform and Kotlin native. Obviously the K/N memory model isn't bad, infact I would say it's good, it's just a different paradigm from the rest of the targets in Kotlin multiplatform. I don't do any communication via mutable data, there is "mutable data" but in practive it's read only. Really I need a CopyObjectGraph function to give each worker a copy of the data at start of day. Obviously, if I was writing from scratch in Kotlin/Native it wouldn't be an issue.