lua-users home
lua-l archive

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


On 1/14/07, Wim Couwenberg <wim.couwenberg@gmail.com> wrote:
Your greatest concern is the garbage collection cycle.  It can kick in
any time you do something in a child state, not only when you
explicitly request it.  This makes your approach unsafe.  Bottom line:
always allow only a single OS thread to drive the lua_State at a time
(use some mutex construct).

This is only a problem with certain classes of code mostly dealing
with userdata types.  For example releasing COM objects may need to be
done from the correct thread.  As far as I know the Lua types and
their collection are thread-safe.

The lua_lock and lua_unlock macros are not recommended: they slow
things down *a lot* because they are used often.

I think this is a misconception.  Where is it not recommended?   It's
highly dependant on how efficient your locking mechanism is and you
get to determine the locking mechanism.  For example on Windows I see
no measurable slowdown at all when using CriticalSection locking.  In
my pthread version I see about a 25% slowdown but I'm using a slow
implementation that has plenty of room for improvement.

CR