Reputation: 12700
Lua provides a "registry" "that can be used by any C code to store whatever Lua values it needs to store". And threads "shares with the original thread its global environment", as said here. But I can not find any place where it says if it shares the register.
So that's basically my question: if the threads are derived from the same original state, do they share the table accessible at LUA_REGISTRYINDEX?
Upvotes: 2
Views: 824
Reputation: 508
The Lua registry is part of the lua_State*
, thus anything using or contained within a given Lua_state (Such as Lua threads: Co-routines) will also share its Registry.
Lua Threads (co-routines) are part of the lua_State*
they were created from, and thus share the same Registry.
OS Threads will access whatever Registry is associated with the lua_State*
passed to lua_getfield(...)
(et al.).
Bare in mind that Lua's only assurance with respect to OS threading is that the Lua CAPI is reentrant and stores all its values in the lua_State*
; its up to you properly manage the state to avoid simultaneous access and corruption.
Upvotes: 3