lua-users home
lua-l archive

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


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.

-Kevin

> -----Original Message-----
> From: lua-bounces@bazar2.conectiva.com.br 
> [mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of 
> Johann Hibschman
> Sent: Wednesday, July 21, 2004 7:58 PM
> To: Lua list
> Subject: Re: Threads HOWTO?
> 
> 
> On Jul 21, 2004, at 7:35 PM, Rici Lake wrote:
> 
> > On 21-Jul-04, at 5:39 PM, Johann Hibschman wrote:
> 
> > The giant interpreter lock does guarantee that the Lua internal 
> > structures will remain coherent. But it does not at all 
> guarantee that 
> > individual threads will have a consistent view of the 
> world, if they 
> > share state with each other.
> 
> That's all right.  Anything in the global state would be immutable.
> 
> > where a is a global variable could generate unpredictable 
> results. And 
> > Lua does not provide any interpreter-visible synchronization 
> > primitives which would let you prevent that. Of course, the problem 
> > could be avoided by giving each thread its own globals environment, 
> > but then one has to wonder what the point of using Lua threads was.
> 
> Hopefully immutable globals wouldn't require a global envt 
> for each lua 
> thread.
> 
> > Given all that, my inclination in threading Lua is not to; 
> that is, to 
> > keep a separate Lua instance for each thread and to do inter-thread 
> > communication (if necessary) through a separate library.
> 
> Unfortunately, I'm trying to bolt-in a bit of scriptability to an 
> application that creates computation threads all over the place.
> 
> I'm looking for a way to execute some lua code safely from 
> inside some 
> random thread, when I don't have the luxury of setting up a special 
> thread-specific state at thread-creation time.  That's why I was 
> looking at the idea of creating lua threads each time a chunk of code 
> is executed.
> 
> Thanks for the comments,
> 
> -Johann
>