What are the key things to be aware of with thread...
# kotlin-native
n
What are the key things to be aware of with threads in Kotlin Native when it comes to C interop? Have a situation where a segmentation fault occurs when a callback (on the 2nd thread) is invoked by a C API (on the 1st thread which is the main thread?).
d
You need to call initRuntime or something like that from the callback.
👍 1
I think it's
initRuntimeIfNeeded
.
👍 1
🙏 1
Do you pass kotlin objects via this callback?
StableRef
?
🚫 1
n
Presumably all the callbacks used with the Paho MQTT Client library run in the 2nd thread.
Is there a way to determine at runtime with Kotlin Native which thread the callback is running on?
Thinking that the Kotlin Native C interop documentation should be updated to include a Paho MQTT Client callback example that uses the initRuntimeIfNeeded function.
d
Not built in but you could use a Thread Local variable to check.
You might be able to use
Worker.current
.
n
Aren't Workers separate from Threads?