lua-users home
lua-l archive

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


The linked issue seems to suggest that the problems is LuaBase finalizers being called from the finalizer thread but I don't see how that could be possible because it looks like the finalizer doesn't attempt to free the reference at all.

The biggest threading issue I see in LuaInterface is that the CodeGeneration class is a singleton. (CodeGeneration.Instance)
The fastest hack to fix that would be to make it use thread-local storage instead of global memory:

GenerateEventAssembly.cs line 99
--private static readonly  CodeGeneration instance = new CodeGeneration();
++[ThreadStatic] private static CodeGeneration instance;

GenerateEventAssembly.cs line 123
--return instance;
++return instance ?? (instance = new CodeGeneration());


A more memory-conservative approach would of course be to make all the CodeGeneration public members thread-safe.

On Wed, Nov 26, 2014 at 1:12 PM, Geoff Smith <spammealot1@live.co.uk> wrote:
Hi Marco
 
Thanks for the response. I have just found this quote from a post on Stackoverflow
 
"LuaInterface is not thread safe. From what I have read Lua itself appears to support multithreading (see Lua Lanes). However, LuaInterface(v2.0.3.7) still has some issues to work out before it is thread safe. Putting separate instances of the Lua interpreter in their own thread does not overcome these issues."
 
So as you say,  it looks like I am screwed if I want to get two scripts running from different threads using LuaInterface.
 
I did look initially at Nlua but documentation is severely lacking, and I couldn't get it to work at all if I remember correctly.
 
Of course the question still applies anyway ? Is Nlua threadsafe when running two Lua instances from two threads.
As it was originally forked from LuaInterface, there is a fair chance it would have the same exact problem ?
 
I have already put quite a bit of time and effort to get where I am using LuaInterface, so swapping horses now wasn't something I really wanted to do. Hmmmm have to ponder this some more.
 
Geoff
 

 
> Date: Wed, 26 Nov 2014 19:28:11 +0100
> From: marco@mastropaolo.com
> To: lua-l@lists.lua.org
> Subject: Re: Tricky c#/LuaInterface Question
>
> I'd say upgrading to a different library is the solution, as
> LuaInterface seems to be abandoned.
>
> I've detailed your best bets on the previous email, but to give you some
> elements to choose from:
>
> I'm the author of MoonSharp and with it, it should work with no problem
> whatsoever. As it's a complete reimplementation you might find very
> minor differences (and os/io is not there yet); but it should be very
> easy to use and includes a debugger. It targets Lua 5.2.
>
> I also think KopiLua and NLua will have no problems with that scenario,
> and they are closer to LuaInterface as far as API goes, so you have a
> lot less code to change, plus compatibility (w/Lua 5.1) is likely to be
> higher.
>
> In both cases beware of sharing objects between the two contexts without
> some very careful attention on your part.
>
> I don't know the others in depth and used them only sporadically, but I
> don't rule them out to possibly be great choices.
>
> Links:
> MoonSharp : http://www.moonsharp.org/
> NLua/KopiLua : http://nlua.org/
>
> -- Marco
>
>
> On 26/11/2014 18:26, Geoff Smith wrote:
> > Does anyone have some insight into is it possible to run 2 totally
> > independent threads with LuaInterface ? Any help would be appreciated.
> > Thanks
>
>