lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Graham Wakefield wrote:
> What I gathered from the list is that a coroutine that errors cannot be 
> recycled, but one that returns with no error can have its stack cleared and 
> be ready to be re-used.  I just wondered if there was any more to it that 
> this; should I worry about any changes of environment, metatables etc. that 
> may have had side effects on the lua_State, and which would lead to 
> undefined behavior if recycled?

Yes, this is the current state of affairs. Recycling coroutines is
only feasible if you can control the complete execution (i.e. not
for sandboxing).

Usually this would be a pool of coroutines handling a specific
task. Their outermost function runs a loop, fetching a work item
from a queue. A worker function is called and when it returns the
loop can continue without destroying the coroutine.

--Mike