lua-users home
lua-l archive

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


Even if they don't share the structure, if you cache the states in a pool,
you won't load the structure that many times. Furthermore, you can share
external objects pointed to by userdata so long as the objects do the
appropriate mutex work. In other words:

    Lua 1 --> userdata --> native object <-- userdata <-- Lua 2

Where Lua 1 and Lua 2 are separate universes each with a pointer-sized
userdata containing a pointer to the shared native object.

Mark

on 7/22/04 9:36 PM, Johann Hibschman at jhibschman@yahoo.com wrote:

> On Jul 22, 2004, at 12:05 PM, Kevin Baca wrote:
> 
>> If your global state is immutable then, instead of all threads sharing
>> a
>> single state, can you have multiple identical lua states, each in its
>> own thread?  Maybe a lua state pool?  When you need to call a compute
>> function, grab a state from the pool and compute away.
> 
> That's a good thought; the problem is that there are large shared
> structures that take a while to load/reconstruct from the
> database...but there's no reason that multiple lua instances can't
> point to the same object, just as long as they don't try to collect it.
> Never mind.
> 
> I'll just have to play with this for a while and see what I come up
> with.  Thanks for the pointers; after I have a bit of experience, I'll
> try to write something up on the wiki.
> 
> -Johann
>