[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 5.1 threads, environments, and 5.2
- From: Roberto Ierusalimschy <roberto@...>
- Date: Mon, 11 Apr 2011 11:32:17 -0300
> 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