Hacker News new | ask | show | jobs
by vasama 2487 days ago
I think you mean fibers, and no you can't.
1 comments

Here is an implementation of coroutines on top of setjmp/longjmp: https://fanf.livejournal.com/105413.html
How does it work for arbitrary arguments? What about function pointers. What about calling a coroutine inside a coroutine?

It also has a stack managed in runtime. I'm not sure that would work for any other application than the fun example here.

Looks more like an implementation of undefined behaviour to me.
"Please don't post shallow dismissals, especially of other people's work. A good critical comment teaches us something."

https://news.ycombinator.com/newsguidelines.html

The underlying implementations define the behavior here very well.
Well, I would not go that far. My coroutine hack relies on “unwarranted chumminess with the implementation” (http://c-faq.com/struct/structhack.html) and there are lots of incidental things that can break it. It is best treated as an example of the principles of thread switching and stack allocation.