lua-users home
lua-l archive

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

On Jun 15, 2008, at 1:47 PM, Mike Pall wrote:

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).

OK so I didn't miss anything!

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.

Unfortunately in my project, the end-user is expected to create and destroy coroutines; they're an integral component of the user API. I can't stop them from calling return!

Thanks for all your help, and looking forward to try luajit 2!