lua-users home
lua-l archive

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


On Wed, Mar 30, 2011 at 2:11 PM, Anthony Howe <achowe+lua@snert.com> wrote:
> >From the 5.2 alpha documentation, section 8.1 – Changes in the Language:
>
> "Threads do not have individual environments. All threads share a single fixed environment.
>
> This doesn't sound good.

It is good. Threads don't have "environments"; functions do. What the
quote above really means is Lua no longer has a per-thread context.
(Of course, this per-thread context only applied to C closures using
LUA_GLOBALSINDEX...) It doesn't really make sense and can be easily
emulated through function environments and closures.

> In my current network application I am developing, I rely on the ability for threads to have separate "environments" (contexts) in
> order to ensure that data placed into the thread's global space does NOT appear in another thread's global space or the master state
> from which the thread was originally created.

You can still do this. Thread specific data can be kept in a weak
table within the registry. Alternatively you can maintain state
through closures and upvalues.

> How will a thread ensure that data defined within it remains confined to that thread? Currently I rely on changing the thread's
> LUA_GLOBALSINDEX to a metatable assigned to the thread that confines data.

There is no LUA_GLOBALSINDEX in 5.2.

Again, use a weak table in the registry for thread specific data.

-- 
- Patrick Donnelly