I’ve been experimenting with Kotlin native and multithreading. I’m working on a pretty low level, directly calling
pthread_create and other low-level primitives.
I have noted that Kotlin native really doesn’t like me to access datastructures from new threads unless they have been frozen.
Is there a technical reason for this? I have some pretty low-level code where I want to use regular locks and shared datastructures, but there seems to be no simple way to achieve this.
I’m well aware of the arguments against shared datastructures and in favour of immutable shared data. For the most part I agree with them, but sometimes the best solution is to use traditional locks, and my question is how to achieve this in Kotlin native. And if it isn’t possible, I’d like to know the reasons for it. I’m wondering if it has something to do with how the garbage collector works?