Given the behaviour of kotlin-native with regards ...
# kotlin-native
d
Given the behaviour of kotlin-native with regards to freezing all singletons by default (https://github.com/JetBrains/kotlin-native/blob/master/CONCURRENCY.md), and the circumstance of having singletons with mutable data in common sources of a multiplatform project, is it possible to disable these limitations? The file I linked doesn't really explain the benefits of the described behaviour, and while I understand that there are some benefits, I think it is honestly quite silly, especially in multiplatform projects, that there is no way to disable it. What is the technical reason behind that, assuming there is one?
k
They’re not limitations. It’s an intentional decision to facilitate a better design for concurrency. My thoughts https://link.medium.com/YMdzOQYOSR
👍 2
“Constraints” would perhaps be a better description
o
Note, that top level variables have different set of limitations, so for single-threaded server on coroutines it may fit your needs.
d
Yeah, I understand that the reason has to do with the memory model now. Very interesting. Did you say top level variables have different behaviour than singletons?
Thanks for the read @kpgalligan!
o
Yes, by default top level variables are fully accessible from the main thread and cannot be accessed from other threads.
d
Can they also be mutated?
Sorry, I should check your concurrency doc again. Thanks for the answers.
k
The top level var is only visible to the main thread and is mutable (unless you want it shared and frozen, in which case you can add an annotation)