[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Co routine local data / best practices
- From: Jim Pryor <lists+lua@...>
- Date: Wed, 2 Dec 2009 13:16:21 -0500
On Wed, Dec 02, 2009 at 09:33:47AM -0800, Chris Gagnon wrote:
> M = thread/co routine manager
> S = some system that has registered a C interface for lua scripts to use
> This may yield, i'll use the specific example of a system that
> impliments a Delay(fTime) function for scripts to use.
> L = a co routine
> M creates L and could create MyStateWrapper then starts L
> L calls Delay(1.0) S gets a call to its registered function of signature
> int function(lua_State *L) and yields L
> ...1 second later...
> S wants to Resume L however the resume requires MyStateWrapper so that is
> can properly clean up if the L ends or errors.
> Now i must look up in a map that associates L with MyStateWrapper.
Are you using pre-emptive threads? If so, are you using one of the
existing Lua frameworks for this or have you rolled your own?
If you're only using cooperative threads, then would the model be that S
yields the thread that called it back to a parent Lua thread, such as M,
and that later someone (looks from this model like it should be M, but
that doesn't sound like what you have in mind) decides that the
suspended thread should be resumed. So other cooperative Lua threads can
be run in the meantime. In that case are you using some patch (RVM?
Coco? to enable you to yield across the C-call boundary?
Or is the model that S suspends the whole Lua universe for one second
(other Lua universes rooted in other parent lua_States can run, but the
two universes wouldn't share any memory). In that case you wouldn't need
to be doing any yielding inside the Lua universe that's being suspended,
you just don't return from the C-call to S until you're ready to go on.
Sorry I'm not getting what you have in mind.