On Sep 15, 2006, at 5:15 PM, Luiz Henrique de Figueiredo wrote:
How much can I copy Lua data around between distinct
states (assuming thread safety is managed correctly)?
If you have got your locking right, you can use lua_xmove if the Lua
states are related (ie, children of the same Lua top state).
Aha! I didn't realise what lua_newthread did (I thought it was
something to do with coroutines). OK. So if I understand
correctly, I can have a root lua_State in one thread, create new
lua_States from it using lua_newthread(), which will be managed in
other threads, but create thread-safe interchanges between them
using lua_xmove.
So lua_xmove is really creating copies from one stack to another.
How are references resolved - are they deep copies?
lua_newthread retains references to global data; how can this be
thread safe if both the old & new threads (running in different
system threads) can access them? Are they also independent copies?
Sorry if I'm not understanding something here.
According to the manual:
lua_newthread
lua_State *lua_newthread (lua_State *L);
Creates a new thread, pushes it on the stack, and returns a pointer
to a lua_State that represents this new thread. The new state
returned by this function shares with the original state all global
objects (such as tables), but has an independent execution stack.
There is no explicit function to close or to destroy a thread.
Threads are subject to garbage collection, like any Lua object.