lua-users home
lua-l archive

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


On 11/04/2011 16:32, Roberto Ierusalimschy whispered from the shadows...:
> 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

I hadn't considered this idea. Personally I like the idea of this being
transparent. Just easier for my colleagues and 3rd party script writers,
one less thing to worry about.

> 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.

I tried to do this through a metatable __index change of the master
state which function defined at load time would inherit in their
environment, but it never worked, though that might just be a flaw in
the logic of my replacement __index.

But since you've suggested this should be possible, I'll revisit it.

-- 
Anthony C Howe            Skype: SirWumpus                  SnertSoft
                        Twitter: SirWumpus      BarricadeMX & Milters
http://snert.com/      http://nanozen.info/     http://snertsoft.com/