[haiku-development] Re: The Call for Scripting Languages: Lua

  • From: Rob Hoelz <rob@xxxxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Sun, 27 Sep 2009 12:51:03 -0500

Donn Cave <donn@xxxxxxxxxxx> wrote:

> Quoth Stephan Assmus <superstippi@xxxxxx>,
> 
> > I would only use the second approach, if you can be sure that the
> > patch is rock-solid. If it is, then why isn't it part of the
> > official lua source code, yet? I would be suspicious, even though I
> > realize I might hurt the feelings of whoever produced the patch. :-)
> 
> A good point.  Python had a patch like that years ago, from a very
> well regarded developer but never accepted, so of course many
> versions later it's now impossible to apply it to a modern Python
> release.
> 
> > Then there is the issue of re-entrant versus multi-threaded.
> > re-entrant basically means that you don't have some static/global
> > variables getting in the way. It does not automatically mean that
> > the program would work as a whole with regards to the interpreter
> > state.
> >
> > So the first approach does sound more robust to me.
> 
> It's more or less how the Python binding works.  To introduce another
> distinction, Python supports multiple threads, but the threads will
> not execute Python instructions concurrently - they're serialized by a
> mutex, and the BLooper has to acquire that mutex before returning
> to the interpreter.  That works fine, and in fact since with Python
> I never had the troubles other people report with Be API
> multithreading, I have wondered if this system is accidentally more
> robust.
> 
> The thread support helps, though.  For example, all external functions
> release the interpreter lock, so another thread can execute in the
> interpreter while an I/O completes.  Imagine the whole application
> stalling while some thread calls recv() - that would be awkward.
> 
>       Donn Cave, donn@xxxxxxxxxxx
> 
> 

I should clarify - the patch I was referring to is LuaThread, a patched 
distribution of Lua to allow multi-threaded programs, which comes along
with its own set of concurrency/synchronization primitives.  As far as
why it has not been merged into standard Lua, the Lua authors seldom
take in patches verbatim, and also, Lua has an extremely minimalist,
portable mindset, so anything that would prevent scripts from running
on a platform is omitted.  I'm not an official spokesperson for Lua,
however, so if you want an official answer, feel free to join us on
#lua or ask the mailing list. =)

There is a way to enable a global interpreter lock (or something like
it), but the functionality needs to be configured at compile time.
I think this would be acceptable until someone complains; however,
since Lua is designed to be modified by the programmer for their
application's needs, I would likely just tell the person to write their
application using LuaThread.  A Haiku distribution of Lua and a Haiku
distribution of LuaThread would offer the best of both worlds, I feel.

-Rob

Other related posts: