[quote=“guessed, post:4, topic:175088”]Vera creates one [tt]LuaState[/tt] per Plugin. Access to each [tt]LuaState[/tt] is controlled via at least one lock, to avoid the concurrency problems on the [tt]LuaState[/tt] context itself.
As others have mentioned, each [tt]LuaState[/tt] is not threadsafe, BUT Lua totally supports having multiple, isolated, ones running within the same process as long as they each have separate execution contexts.
Access to the [tt]LuaState[/tt] might occur when you’re running an [tt]ACTION[/tt] handler, a Timer callback, or an [tt][/tt] section (for example).
In UI4 there were, from memory, 2 threads “globally” in a pool for all things running on Vera. This led to a multitude of deadlock like situations for UI4 users with a lot of plugins (for a variety of reasons)… it also led to a lack of locking, in some situations (see below)
In UI5, there are supposed to be 2 thread per Plugin, so that one Plugin cannot [as] readily jack-up another.
I don’t use [tt]luup.inet.wget[/tt] for anything, since it’s invoking more MCV code. I do have a multitude of things [frequently] running LuaSocket calls, and they’re not giving me any noticeable problems.
eg. 3x Sonos Plugins, calling every 15 seconds, 1x Weather Plugin calling every 30 mins
I’d be extremely surprised if LuaSocket has a t-safe issue. It’s fairly hard to get it wrong when you have your own context to store stuff in.
UI4 users are basically hosed, since there were a load of situations where the locking wasn’t in place (adding it in UI5 is why MCV needed to add more threads)
As a result, when concurrent “events” occurred in UI4 (see above for examples) it had a high likelihood of corrupting the [tt]LuaState[/tt] object. When this happened, all sorts of ugly occurred, and often a restart of the LuaUPnP process was required.
Presumably your user is not on UI4…
Disclaimer: For full disclosure, every Vera version after 1.5.408 has caused my Vera 3 to “spontaneously” reboot when running one of my heavier scenes, or at other random times throughout the day (1-10x per day). AFAICT, this appears to be more of a problem with the [tt]NetworkMonitor [/tt]itself returning false positives, and excuting OS-level reboots.[/quote]
Thank you very much for that detailed reply! Very helpful.
But I would say that, even if Lua C libraries are smart enough to keep their own data in the current context where they should, they could still very easily rely on lower-level code that uses data in non-threadsafe ways, and the original library author–who quite possibly never saw threaded code in his life–would never have considered or tested for the case where the whole stack is being used in multiple threads in the same process.
(I haven’t looked at the LuaSocket C code, and of course I have no knowledge of how MCV builds it or the interpreter.)
watou