lua-users home
lua-l archive

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





On Sun, Jul 13, 2014 at 8:46 PM, Tim Hill <drtimhill@gmail.com> wrote:

On Jul 13, 2014, at 5:39 PM, Thiago L. <fakedme@gmail.com> wrote:

>
> On 13/07/14 09:36 PM, Austin Einter wrote:
>> Hi All
>> Suppose I have Lua State L as a global variable in my C program.
>>
>> If it is accessed and used by two different threads, is it required for me to protect the Lua State by using a semaphore/mutex.
>>
>> OR
>>
>> Lua State internally has a semaphore/mutex to protect itself.
>>
>> Please let me know.
>>
>> Austin
> I'm pretty sure they aren't thread-safe...
>

You have to do this yourself.

—Tim


You define lua_lock/lua_unlock, providing your os-specific mechanism.

This will slow Lua down during garbage collection and also generally. If you can, avoid doing that. 

Lua is reenterant, so running multiple Lua_States is no problem. If you can, run one Lua state per-thread and marshal values between, doing the message-passing yourself, or using ZMQ or NanoMSG or similar.

-Andrew