Hello I'm developing mp-project where I need a sh...
# multiplatform
a
Hello I'm developing mp-project where I need a shared strucutre (actually map of immutable key-values), that potentially may be accessed from different threads, but writes will be executed from single thread. Currently I'm considering approach with coroutines and custom SignleThreadDispatcher (Default on JS, Executors-based on JVM and Worker-based on Native), but I cannot find a way of hiding freezing concept from common code. Is there some possibility to do it? I want to inject serialization of writes here: https://github.com/d-r-q/qbit/blob/master/qbit-core-jvm/src/commonMain/kotlin/qbit/serialization/NodesStorage.kt#L14 And here is map-based storage implementation: https://github.com/d-r-q/qbit/blob/master/qbit-core-jvm/src/commonMain/kotlin/qbit/storage/MemStorage.kt
Ok, in this post: https://helw.net/2020/04/16/multithreading-in-kotlin-multiplatform-apps/ I found, that "Note that objects will be frozen when they are transferred between threads using `withContext`" Will check it
hm, but looks like I still need some thread-safe data structure for jvm due to java memory model semantics
For history: newSingleThreadContext was added for native in 1.3.5-native-mt-1.4-M1 but reads also should be done via the same thread as writes either map should be immutable