https://kotlinlang.org logo
#kotlin-native
Title
# kotlin-native
b

bod

07/25/2022, 9:45 PM
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

Arkadii Ivanov

07/26/2022, 6:31 AM
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

bod

07/26/2022, 6:45 AM
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

Arkadii Ivanov

07/26/2022, 8:00 AM
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

bod

07/26/2022, 8:07 AM
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

Arkadii Ivanov

07/26/2022, 8:11 AM
Cool! Good to know!
2 Views