I would like to support coroutines / generators in my virtual machine, even if I don’t decide to use them. I’ve heard that they are quite hard to implement. I’m planning on having a thread system anyway, coroutines seem just like an extension. I was thinking that a coroutine is a new thread that runs completely off a mutex of sorts, where the original thread doesn’t run until the coroutine ‘yeilds’ and the coroutine doesn’t run again until a thread calls it. While the resulting implementation might not use actual mutex’s (eg properly substitute threads) this sounds like a viable way to implement coroutines.
Sound like it will work? Something I’m missing? Should I be bothered anyway?
0 Responses to “Coroutines”