I want to be sure I understand what is going on here to be sure.
Can someone offer an example of where this ability would be particularly useful?
I want to be sure I understand what is going on here to be sure.
Can someone offer an example of where this ability would be particularly useful?
I'm a particular fan of how coroutines work in Lua. Here's an article that helps explain them a bit in that context: http://leafo.net/posts/itchio-and-coroutines.html
We used to use them(Lua) in games to do scripted sequences and AI. Was simple enough that even our designers could edit/extend them.
It's a different model of control structure, primarily when you have a thing that produces data and a thing that consumes it. It could be in multiple threads, multiple machines, or just a single thread, so is often included in multiprocessing portions of designs, standards and instruction.
I recommend watching this video, which has a great overview. https://www.youtube.com/watch?v=_fu0gx-xseY
So you create another thread, have the main thread yield time to it, and at fixed points in this other thread yield back to the main thread. When the main thread yields to this other thread, all it's context is maintained and you don't need to "walk up" the stack to restore the work this thread was doing.
At a high level, this solves the class of problems where you need to do background tasks in applications that aren't thread safe. There are probably other places where these work well, but this is just my experience.