Are there any threading restrictions I need to wor...
# kotlin-native
s
Are there any threading restrictions I need to work around from calling Kotlin code from swift?
o
Generally keep calling Kotlin on same thread, or pass all context like in https://github.com/JetBrains/kotlin-native/blob/master/samples/globalState/src/main/kotlin/Global.kt
s
What do you mean by pass all context? I'm not understanding from the code sample either.
o
note
konan.worker.detachObjectGraph { SharedDataMember(3.14)}
as an argument to
pthread_create
, and
val arg = konan.worker.attachObjectGraph<SharedDataMember>(argC)
in thread callback. Generally, we disconnect objects from one thread, and reconnect it in another
thus, if your function callback has some Kotlin state - you could use same technique
s
I see, that's what you were talking about. That makes sense. I've heard Andrey Breslev mention that there was probably going to be an additional way to share objects between threads specifically for immutable objects or something? Is that actually going to happen? Is that going to happen any-time soon?
o
Yes, we are working on that right now
s
That's fantastic news 🙂 I look forward to that. That promises to be a much better way to write concurrent code in kotlin native.