News for hackers. Stuff that matters.
Re:Simple coroutines for games in C++ by quotemstr on Monday March 21, 2016 @01:20AM (#11326381)
setjmp also works fine, and besides, "1,000 times slower" is meaningless if the thing that's 1,000 is not actually the bottleneck.
Re:Simple coroutines for games in C++ by AnkhMorporkian on Monday March 21, 2016 @06:36AM (#11327169)
I'm a bit out of my wheelhouse here, I usually do C and rarely touch C++, and in addition the coding standard I have to adhere to prevents setjmp/longjmp, but doesn't setjmp need to be used in conjunction with longjmp, which makes it completely unsafe to use malloc, fopen, etc? Also, it would prevent RAII from running.
Re:Simple coroutines for games in C++ by quotemstr on Monday March 21, 2016 @08:38AM (#11327613)
getcontext and setcontext are fundamentally about saving and restoring CPU registers. setjmp and longjmp are also about saving and restoring CPU registers, and they (and related functions) give you much more complex of whether you want to save the signal mask. Since saving and restoring the signal mask is the objectionable part of setcontext, setjmp is a decent alternative.

If you want to unwind, just unwind. setjmp and setcontext neither help nor hurt you here.

Re:Simple coroutines for games in C++ by AnkhMorporkian on Monday March 21, 2016 @09:30AM (#11327898)
Fair enough. I still have doubts about whether that would scale up to millions or billions of coroutines, but I will defer to your knowledge in that it's probably Good Enough™ for most purposes. Thanks for the explanation!