zlacker

[parent] [thread] 1 comments
1. anfilt+(OP)[view] [source] 2026-02-04 20:54:04
Speaking of Coroutine libraries, I wrote this stackful one a few years ago: https://github.com/Keith-Cancel/Bunki

It has the ability to add context to each coroutine.

replies(1): >>ambonv+RE3
2. ambonv+RE3[view] [source] 2026-02-05 21:33:16
>>anfilt+(OP)
Yes, I did actually look at Bunki as well before building this. Liked the imagery. :)

What did not quite fit for my purpose was having the asymmetric coroutines as the fundamental layer, meaning that the dispatcher also is tied to that layer. Building the next level dispatcher on top of that is probably possible, but seemed a bit complicated.

I instead started with symmetric coroutines as the fundamental building block and built the dispatcher at the next (process) layer where it can deal with the event queue to determine who goes next. The process level resume() call is always made from some event executed by the dispatcher on the main stack, making the processes asymmetric coroutines even if the lowest level coroutines are symmetric with transfer() calls.

Making asymmetric coroutines from symmetric ones is easy, just yield(void) { transfer(parent); } and resume(target) { transfer(target); } in slightly abbreviated code, while going the other way around requires an extra context switch via the dispatcher on the way there.

[go to top]