lua-users home
lua-l archive

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


Hi,

I'd like to know which operations upon a lua_State * (i.e. which Lua C API calls) are safe to make on child lua_State *s in different OS threads.

Here's the scenario:

I create a parent lua_State * in the main OS thread, load in libraries etc. I won't actually call functions in this state, it is just a parent.

Then for each OS thread, I create its own child lua_State * of the parent state using lua_newthread(). Most API operations (lua_push... (), lua_to...() etc) seem to be safe to be made without affecting the other lua_States and despite thread interruption.

For any Lua API calls that are global to parent & child states, I use a mutex lock (e.g. lua_gc). I am very careful about using lua_xmove between the states, by using an intermediate lua_State * as a kind of buffer, and the mutex lock.

I would like to know, of all the API, which API calls are safe within a different OS thread, and which will affect both lua_State *s no matter which is called (and therefore should use locks). Essentially, because I know that my threads interrupt very frequently, I really want to minimize the use of and duration of locks.