lua-users home
lua-l archive

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

On Jun 24, 2014, at 5:53 AM, Austin Einter <> wrote:

Hi Thijs Schreijer

You told
You can only acccess a lua state from a single thread. So assuming you stay single threaded, then for each invocation you can simply clear the stack, and do your thing. Nobody will interfere with that.

In above are you telling that lua state can be accessed from a single thread. If in one process I have 10 threads, and from 10 threads I am trying to access lua state, will it be a sequential execution hence a performance issue. will not 10 threads access lua state in parallel.

Just to clarify. Lua itself is “thread friendly” in that the entire Lua code base uses no global state and is fully reentrant. However, each individual lua state, created using lua_newstate() etc can only be used single-threaded. So you can create a dozen user states and have each one running on its own thread, but each state can never be accessed by more than one thread at a time (and you are responsible for ensuring this, not Lua).

Since each lua state also has its own stack, this means that all stack operations are also single-threaded and so issues of stack synchronization across threads should not arise. If you need to synchronize thread access to a Lua state, you should do so in your C code using standard OS primitives such as mutexes.