Hello, World! I have a behavior difference when us...
# kotlin-native
b
Hello, World! I have a behavior difference when using the new memory manager or not with this very simple app (on Apple):
Copy code
fun main() {
    runBlocking {
        withContext(Dispatchers.Main) {
            println("Hello, World!")
        }
    }
}
With the new memory manager enabled, the message is never printed, the thread seems to be stuck on
withContext
. I’m not sure if this is to be expected - something like
runBlocking
blocking the main thread and making dispatching ineffective? … But then again it feels like this should work, and also looks like a regression since it works with the old MM? 🤔 Any insight would be appreciated! 🙏 Repro project here.
a
This looks like a reasonable deadlock. runBlocking blocks the main thread, and so withContext can't submit its job.
It's an equivalent to Rx:
Copy code
completableFromFunction { println() }
    .subscribeOn(mainScheduler)
    .blockingAwait()
b
That sounds reasonable but still wondering why it works without the new MM.
as a side note: using
Dispatchers.Main.immediate
avoids the hang
a
I thought the immediate dispatcher is only available on Android, unless something has changed recently. Also it looks like you don't need to switch context at all, because you are already on the main thread.
b
Interesting about
immediate
! Wondering if the doc is outdated. Will look at the source 🙂 You are right about not really needing this, just exploring and trying to understand why some of our tests are now failing (well, not failing but hanging).
I think that's it
a
Cool! Good to know!