An idea; Coroutines
Richard Andrew Cattermole (Rikki)
richard at cattermole.co.nz
Tue Jan 16 15:00:18 UTC 2024
On Tuesday, 16 January 2024 at 14:46:03 UTC, Stefan Koch wrote:
> We have fibers in the runtime; why would we need the coroutines
> you propose and what's the difference to the fibers we already
> have?
To quote:
https://www.open-std.org/JTC1/SC22/WG21/docs/papers/2018/p1364r0.pdf
Which comes from Microsoft:
https://devblogs.microsoft.com/oldnewthing/20191011-00/?p=102989
> We have accumulated more than a quarter century of experience
> with fibers across variety of programming languages and
> platforms. In the 90s fibers and N : M scheduling looked
> promising, now, with improvements in hardware, operating system
> kernel and painful experience of trying to make the fibers work
> has resulted in a recommendation: **DO NOT USE FIBERS!** Use
> threads instead and/or write your code using asynchronous APIs
> with hand-crafted state machines.
Fibers as we have them are a runtime hack using inline assembly.
Microsoft had to add them to WinAPI specifically because people
kept messing up their implementation with the calling conventions.
Ours on OSX broke a few years ago too (was fixed quickly).
But the key difference to understand about stackless coroutines
instead of fibers, coroutines understand the dependency that a
coroutine that has yielded has, a fiber does not.
More information about the Digitalmars-d
mailing list