The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Cooperative Mutlitasking: Coroutines / Fibers
graphitemaster


Joined: 11 Sep 2014
Posts: 1
There has been a recent rise in such multitasking facilities in media applications, for instance they're the easiest way to implement
the functional equivalent of a 'think' function for video games, similarly, home-made scripting languages for game engines could
benefit from them as well.

Implementing them however is highly platform and toolchain specific as there is no standard way to achieve them. More often than
not you can get away with a bit of assembler to manipulate the stack pointer and jump address, longjmp and family can also be
used to achieve this at the cost of breaking perfect forwarding for C++ and exception safety guarantees. Even on POSIX which
has makecontext/setcontext, such API is actually optional and also deprecated since 2008, which is why some libc's fail to
support it (bionic, musl).

There is also a security issues, adjusting the stack pointer and call sites can lead to easy attack vectors which is why I'd discourage
people from implementing them on their own. The reality is such libraries for doing these things do exist, but they're not a component
of SDL. I feel that given SDLs wide array for abstracting platform specific stuff, adding support for these would be a perfect fit. I also
feel compelled that users of SDL would benefit from them for their projects.

I'm up to the task of implementing them for SDL, but I want to know first if this is in the scope of SDL, and more importantly; if it is
part of the scope of SDL would such a patch for supporting them be included or would it become a separate library akin to that of
SDL_image, SDL_mixer, SDL_ttf?

Thanks