3 ms·
It's also possible to implement coroutines using setjmp[1]. IIRC, first you malloc() a new call stack, then populate a buffer using setjmp, patch the buffer to
by DenisM 12y ago
It's also possible to implement coroutines using setjmp[1]. IIRC, first you malloc() a new call stack, then populate a buffer using setjmp, patch the buffer to refer to the new call stack, longjmp to your new coroutine. I've implemented that about 20 years ago. There was some minor tweaking involved for different platforms, except for VAX/VMS - that one turned out to be a real pain.
What I learned from the whole experience is that coroutines are a lot less mysterious than they look. Although I never had a chance to use them since then.
[1] http://en.wikipedia.org/wiki/Setjmp.h http://en.wikipedia.org/wiki/Setjmp.h