lua-users home
lua-l archive

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


> By partially working I mean that I have managed to set the thread's
> global environment so that each thread has its own environment that is
> separated from the master state's environment, so that "globals" created
> in the thread remain confined to that thread:
> 
> [...]

What you need is "Thread specific data". You if look at pthreads, you
will see that it is not easy there, either. You need a function like
pthread_getspecific that returns a different table for each thread.
It is trivial to implement such a function in Lua (use a weak table
with threads as keys and tables as values), but you have to call
this function to have access to thread specific data. You do not
have transparent access to them, unless you add a metamethod to
your global table that redirects accesses to this thread-specific
table.

-- Roberto