News for hackers. Stuff that matters.
Re:Lua-Style Coroutines in C++ by aliguori on Wednesday May 04, 2011 @08:36AM (#2513592)
Most C++ implementations throw their hands up at setjmp/longjmp/setcontext/makecontext.

Even if it appears to work, it's a dangerous set of routines to use in C++.

Re:Lua-Style Coroutines in C++ by pja on Wednesday May 04, 2011 @09:11AM (#2513679)
Yeah, this is going to mix very badly with exceptions.

Also, a little rootling around on the web reveals the following statement in IBM's z/OS docs:

"Do not issue getcontext() in a C++ constructor or destructor, since the saved context would not be usable in a subsequent setcontext() or swapcontext() after the constructor or destructor returns."

Re:Lua-Style Coroutines in C++ by mfichman on Wednesday May 04, 2011 @11:25AM (#2514107)
Indeed. This was more of an experiment than anything else. Ideally, I should have a function that catches all exceptions before calling the user's function to make it safer.
Re:Lua-Style Coroutines in C++ by ncarlson on Wednesday May 04, 2011 @08:41AM (#2513606)
That's how I've always felt. Coroutines are fun to play with in C++, but I'd never be caught dead using them in production code.
Re:Lua-Style Coroutines in C++ by gorset on Wednesday May 04, 2011 @08:42AM (#2513609)
Do you think they are safer or more dangerous than threads?