lua-users home
lua-l archive

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


I would like to know, of all the API, which API calls are safe within
a different OS thread, and which will affect both lua_State *s no
matter which is called (and therefore should use locks).
Essentially, because I know that my threads interrupt very
frequently, I really want to minimize the use of and duration of locks.

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).

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

Another option is to create really separate lua_State instances (so
not via lua_newthread).  Then you'll have to manage to move data
between those states in some way.

--
Wim