Safe cross platform coroutines
All coroutine implementations I've encountered use assembly or inspect the contents of jmp_buf . The problem with this is it inherently not cross platform. I think the following implementation doesn't go off into undefined behavior or rely on implementation details. But I've never encountered a coroutine written like this. Is there some inherent flaw is using long jump with threads? Is there some hidden gotcha in this code? #include <setjmp.h> #include <thread> class Coroutine { public: Coroutine( void ) : m_done( false ), m_thread( [&](){ this->start(); } ) { } ~Coroutine( void ) { std::lock