https://kotlinlang.org logo
Title
s

spierce7

03/02/2018, 3:03 PM
Are there any threading restrictions I need to work around from calling Kotlin code from swift?
o

olonho

03/02/2018, 3:18 PM
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

spierce7

03/02/2018, 5:05 PM
What do you mean by pass all context? I'm not understanding from the code sample either.
o

olonho

03/03/2018, 9:48 AM
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

spierce7

03/03/2018, 3:31 PM
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

olonho

03/03/2018, 4:42 PM
Yes, we are working on that right now
s

spierce7

03/03/2018, 7:35 PM
That's fantastic news 🙂 I look forward to that. That promises to be a much better way to write concurrent code in kotlin native.