Second Draft: Coroutines
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Thu Jan 23 17:07:54 UTC 2025
On 24/01/2025 5:33 AM, Quirin Schroll wrote:
> On Thursday, 12 December 2024 at 10:36:50 UTC, Richard (Rikki) Andrew
> Cattermole wrote:
>> Stackless coroutines
>
> I might want to say, the term confused me quite a while. That’s because
> the coroutine does have a stack (its own stack). I thought it would
> somehow not have one, since it’s called “stackless,” but it just means
> its stack isn’t the caller’s stack. That fact was kind of obvious to me,
> since that’s what “coroutine” meant to me already. In my head I don’t
> see how a coroutine could even work otherwise.
>
> Maybe it’s a good idea to call the proposal “Coroutines” and omit
> “stackless.”
The term is correct.
A stackless coroutine, uses the thread stack, except for variables that
cross a yield point in its function body. These get extracted on to the
heap.
A stackful coroutine, uses its own stack, not the threads.
This is otherwise known in D as a fiber.
Over the last 20 years stackful coroutines have seen limited use, but
stackless has only grown in implementations. If for no other reason than
thread safety. Hence the association. But the word itself could mean
either, which is why the DIP has to clarify which it is, although the
spec may not add it.
More information about the dip.development
mailing list