lua-users home
lua-l archive

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


On Jul 13, 2014, at 11:56 PM, Austin Einter <austin.einter@gmail.com> wrote:

> Hi Tim
> My worry is, with use of our own locks to protect Lua state , will garbage collection pose any thread safety issues.
> 
> Say threads are T1 and T2
> 
> Using lock, I can control T1 and T2, so that only one thread access Lua state at a time
> 
> But garbage collection, in which thread context it executes
> 
> Can it happen that, under T1 I am doing something, and with T2 garbage collection is being executed by system......, hence we will not be able to protect in this case as garbage collection code is not in my control.
> 
> I have not see any issue, just want to make sure I am not doing wrong in my design.
> 
> Austin
> 
> 

No, this is all safe. Each (primary) Lua state has an independent garbage collector, and so it inherits the same thread-safety as other Lua code as long as you make sure only one thread calls into a given state at a time (via whatever locking/mutex you wish to use). There is no hidden GC thread in Lua; it just runs on the same thread that you use when you call into the Lua API.

—Tim