lua-users home
lua-l archive

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



> -----Original Message-----
> From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] On
> Behalf Of Dibyendu Majumdar
> Sent: zaterdag 9 mei 2015 21:16
> To: Lua mailing list
> Subject: Re: lua_lock() question
> 
> On 9 May 2015 at 19:00, Roberto Ierusalimschy <roberto@inf.puc-rio.br>
> wrote:
> > The lock is about the Lua interpreter,
> > not about applications or libraries. When Lua calls C, it is in a
> > consistent state and, from its point of view, it can be called from any
> > thread without any problem.
> 
> Not sure if that is useful - as I would assume the only use case for
> the lock is to prevent the same Lua state being used by multiple OS
> threads at the same time. IMHO it is better to remove the lua_lock() /
> lua_unlock() calls altogether and require that it is the
> responsibility of the application calling Lua to ensure that no two
> threads can concurrently access the Lua state.
> 
> Regards
> Dibyendu

That would be one usecase. But if you have shared data between states, you either have to go to some length to implement safe shared data access, or simply use a single state from multiple threads using the lock macros (at the cost of performance).

Thijs