lua-users home
lua-l archive

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


 

----- Original Message -----

From: Phoenix Sol

Sent: 09/06/09 12:53 pm

To: Lua list

Subject: Re: Cloning "preforked" Lua state

 

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.

I hate to say it, but I think that this is a flaw with Lua. Most of the time you want to declare locals, and that should be the default. Compare the usage frequency of Lua's 'local' keyword to Python's 'global' keyword; the difference is very significant.

 

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.

Sorry, by "thread" do you mean kernel thread or Lua coroutine. This is another thing that irks me, the confusion of terminalogy surrounding Lua's coroutine support; A coroutine is alternately described as a coroutine or a thread, and is of type lua_State. This is confusing to sort out at first, and impedes communication in the case where there is even a slight ambiguity of context.

And then you said, "cloning threads". I thought we were discussing cloning lua_States (sigh) which are not coroutines.

 

The local/global default issue has been discussed before and isn't likely to change.

Sorry for the confusion about threads.  I did use the word in different contexts.  I was speaking mainly of processor threads, which Lua doesn't support, but it can work if you're careful.  Having an easy way around the issues surrounding processor threads has also been discussed before, with some interesting ideas thrown around.

Yes, cloning threads, which meant cloning lua_States, is another one of those interesting ideas.  Somehow I've never looked at Rings, which seems to do what's needed.


Mike