Home > Enterprise >  What's difference between Stackless and stackfull coroutines in Kotlin(Android)?
What's difference between Stackless and stackfull coroutines in Kotlin(Android)?

Time:03-16

After reading some articles I figure out Stackless

  • means that the coroutines don’t have their own stack, so they don’t map on the native thread

*. so the first point is how it differs from stackfull
and in kotlin, if the coroutine helps us to manage asyn process. so how do these two different coroutines (Stackless and stackfull) work. because I am unable to find out its function/syntax/scope or any things else in kotlin coroutine. because I am unable to figure out where is mention which scope or function is Stackless or which of stackfull.

CodePudding user response:

It's not important to know the the distinction to be able to use coroutines in Kotlin.

Kotlin coroutines are stackless: You can only call suspend functions from inside other suspend functions.

To boil it down to a very simplistic definition, a stackful coroutine model would let you suspend or yield from anywhere. A stackless model is restricted to suspending only from inside coroutines, but the benefit is that it is lighter weight. Also, it's probably more feasible to retrofit to an existing language. I don't know any details about the Kotlin coroutines implementation under the hood, but I would bet it would be have been near impossible to implement a stackful model and still compile as Java bytecode.

  • Related