lua-users home
lua-l archive

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


Ignacio Castaño wrote:
> 
> Edgar Toernig wrote:
> > How do you create the new threads?  With lua_newthread?  Unless it's first
> > argument is NULL the new thread will share state (globals, objects, tag
> > methods, ...) with the lua_State you passed as the first argument.  Only
> > when you call lua_newthread will NULL you get an independent thread.
> 
> share state? they use the same global state? i just thought that the new
> thread had a copy of the original thread. The doc says:
> 
> "Each thread has an independent table for global variables. When you create
> a thread this table is the same as of the given state, but you can change
> each one independently."
> Doesn't that mean that at the beginning the global tables are equal (but not
> the same) and that i can add a key to one table without seen it in the
> other?

No.  A misunderstanding.  They both use the same table.  If you change its
contents in one thread the change is visible in all other threads that use
this table.  But you can call lua_setglobals to select another table that 
shall used for globals.

I guess it will be rephrased to something like: "Each thread may have an
independent table for global variables. When you create a thread it uses
the same table as is used in the given state, but you can select a
different one later via lua_setglobals."

Ciao, ET.