Are Kotlin coroutines stackless or stackful? I'm h...
# coroutines
y
Are Kotlin coroutines stackless or stackful? I'm honestly not fully understanding the difference. From what I gather, Kotlin coroutines seems to be stackful, since you can suspend in deeply-nested functions. In the other hand, it sounds like stackful coroutines allow suspending in any arbitrary nested function call, not just one marked with
suspend
. In other words, it sounds like Java's Loom is stackful, while Kotlin's
suspend
is stackless.
o
Stackless, continuation-passing. For each suspend function, the compiler generates a state machine. The coroutine returns at a suspension point, providing data to the caller which is used to later resume the coroutine at that suspension point. The provided data is lightweight, containing only what's relevant for the specific suspension. All coroutines on a thread share one stack, but can still run concurrently. With threading, each thread must have its own independent call stack to switch between threads. https://kotlinlang.org/docs/coroutines-basics.html#comparing-coroutines-and-jvm-threads
❤️ 3