Closed lygstate closed 4 years ago
and also, once a co_thread are finished, what's I need to do to remove it from co_switch? I need some demo for that. This is a wonderfull library that also works on bare-metal:) Just need a bit improvement about the API to easier to use
co_switch()
doesn't automatically switch to another thread, it only switches to the thread you name. If you want to stop switching to a particular thread, you just stop calling co_switch()
on it.
If you never want to switch to a particular thread again, you should stop calling co_switch()
on it, and probably also call co_delete()
on it to deallocate the memory used for the stack.
First, you would find the handle of the coroutine to which you want to yield to using
co_active()
, and then would jump ("yield") to it from another coroutine usingco_switch()
.For more details, look up Symmetric Coroutines vs Asymmetric Coroutines, and how one can be emulated in terms of another. Here's one paper from Lua's developers.