-
Notifications
You must be signed in to change notification settings - Fork 564
Memory.cpp:356: runtime assert: Unable to execute Kotlin code on uninitialized thread #2207
Comments
More information: iOS version of ApplicationDispatcher looks like this: internal actual val ApplicationDispatcher: CoroutineDispatcher = NsQueueDispatcher(dispatch_get_main_queue())
internal class NsQueueDispatcher(private val dispatchQueue: dispatch_queue_t) : CoroutineDispatcher() {
override fun dispatch(context: CoroutineContext, block: Runnable) {
dispatch_async(dispatchQueue) {
block.run()
}
}
} |
If I replace NsQueueDispatcher with Dispatchers.Default on iOS side, my method gets called, but it still fails later on.
|
@yuriry for dispatch_async my worked coroutinedispatcher is:
i think it's can be unstable in some cases, but in my case it's work |
Can you try build with 973cc7b? |
@olonho I built the distribution when I had Xcode 9.x, but now with Xcode 10.0 there are many errors like below when I run
I removed ~/.konan, re-run |
Likely you didn't run command-line tools installation, just run Xcode and it will prompt you to do so. |
Installing Command Line tools now. Strange that when I had Xcode 9.x, the Kotlin Native distribution didn't compile with Command Line tools installed. I had to remove them and re-boot the laptop in order to compile. |
Installed command line tools, installed updates, rebooted the laptop, removed
Any other suggestions? |
It seems dependencies aren't downloaded yet. What's missing is android_arm32 deps. |
@olonho In
The following tasks succeed:
Where do dependencies for the failing tasks come from? Are they supposed to be downloaded by gradle or do I need to install them locally by hand? |
The task
And after installing Command Line Tools, it is also in
Could multiple |
I removed Command Line Tools, removed Xcode, installed Xcode (v 10.0) again, removed
|
I noticed v1.0 was released which includes 973cc7b, so I synced to v1.0 tag and it seems to building fine (at least it is way past the previous point of failure) |
@olonho After checking out v1.0 tag, the build of Kotlin Native compiler succeeded. But then when I tried to build iOS version of my app, I got undefined symbols errors similar to this one. Then I re-compiled and published locally Now, when I run my app, I get the error shown below. I'm not sure if this is because I built and published the libraries from incorrect branches, or if this a legitimate bug. Any thoughts?
P.S. And there is no problem with Android app (as usual). |
This stacktrace seems to be related to the problem you encountered before updating. |
@SvyatoslavScherbina Thank you for the reply. This is interesting. May be my efforts to rebuild Kotlin Native compiler, the plugin and all the libraries were not necessary? I didn't realize the I changed iOS code to create DispatchQueue.main.async {
let client = RESTClient(host:host)
client.getFoo(path:path, extraHeaders:headers) { (foo:Foo?, error:KotlinException?) -> KotlinUnit in
processFoo(foo) // <-- breakpoint 1
return KotlinUnit()
}
} After the change I get deserialized My next step was to call DispatchQueue.main.async {
let client = RESTClient(host:host)
client.getFoo(path:path, extraHeaders:headers) { (foo:Foo?, error:KotlinException?) -> KotlinUnit in
DispatchQueue.global().async { // <-- breakpoint 2
processFoo(foo) // <-- breakpoint 3
}
return KotlinUnit()
}
} At
If I continue the debugger, I get the same stack with Any advice on how to correctly call |
@SvyatoslavScherbina Is it possible that by the time the code on a background thread runs, the instance of |
@SvyatoslavScherbina As an experiment, if I commented out asserts inside of (Allowing creating |
These efforts were absolutely useful, since we have improved incorrect object sharing diagnostics in the version you updated to. That's why you get an exception now instead of runtime assertion.
It depends on how your data is organized. Kotlin/Native imposes strict restrictions on sharing objects among different threads. |
|
Do I understand correctly that |
Most data classes have only |
It is not necessary. Instead you can "freeze" See documentation for more details. |
@SvyatoslavScherbina I hope this is right, at least it works - Common internal expect fun <T> freeze(t: T): T Android internal actual fun <T> freeze(t: T): T = t iOS import kotlin.native.concurrent.*
internal actual fun <T> freeze(t: T): T = t.freeze() |
Thank you for your efforts that made it possible for us to find this solution! |
I've made these notes mostly for my own future reference. Linking them here in case someone needs to build dependencies locally. The steps are probably not optimal, I'll improve them in the future if time permits. Thanks again for your help! |
My code is running into this line when it calls a method from iOS (calling from Android works fine). The method
getFoo()
looks like this:My current version information is as follows:
Any help on how to properly initialize treads when calling Kotlin methods on iOS would be greatly appreciated.
The text was updated successfully, but these errors were encountered: