On Sep 15, 2006, at 5:15 PM, Luiz Henrique de Figueiredo wrote:
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_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.