All threads would use the same ***instance*** of all globals, so if you save something in a global variable in one thread, it affects all threads. This is a very undesirable trait in server threads. If you forget to make a variable local and write to it you have a problem. This then gives us the the problem of context, that is saving state from one subroutine call to another in a given thread. You can't use globals. In the past I've used per-thread tables that I pass to all subroutines, which works, but this idea of cloning threads sounds like it might be a more natural feeling solution to this problem.----- Original Message -----
From: Phoenix Sol
Sent: 09/06/09 11:17 am
To: Lua list
Subject: Re: Cloning "preforked" Lua state
>>From http://stackoverflow.com/questions/1383768/cloning-lua-state/1383847
I was thinking about using coroutines however I'm afraid a fatal error in one coroutine will affect others that's why it's not option atm. Thanks for the links! I'm currently looking at LuaJIT and Rings. Rings seems to be a possible solution for my problem.
What can an error do inside a coroutine (a lua_State created with lua_newthread), that it could not do inside a lua_State created with lua_newstate?
lua_newthread gives you a garbage collected lua_State with all the globals of your original state. Is this not what you want?
Asko, why would a server want to call lua_newstate or luaL_newstate for each request, instead of lua_newthread?
Please tell me what I'm missing here.