lua-users home
lua-l archive

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


On Wed, 31 Oct 2001, Leiradella, Andre V Matos Da Cunha wrote:

> Am I supposed to return something from the C gc tag method

No.


> The reason I'm asking this is because I'm getting random segfaults inside lua
> (ltable.c:luaH_getstr and/or lstring.c:luaS_newlstr) and everything in my
> code seems to be ok except for this doubt regarding gc tag methods. I'm
> using Lua 4.1 alpha and everything is compiled with MingW.

The only suspicious thing in your code is an eventual call to error. GC
tag methods should not call lua_error.


> Another question: is it safe to call lua_unref from a thread other than the
> one that is executing my lua code? I'm using an audio library that runs in
> its own thread and has a callback mechanism to flag when a music or chunk of
> sound has finished playing. I call lua_ref when the music/sound starts and I
> want to call lua_unref inside the callback function. If I can't do that, is
> it safe to put a semaphore around lua_unref (or some other function - which
> one?) to make it safe?

No and no. Unless you compile Lua with proper definitions for
lua_lock/lua_unlock, Lua is not thread-safe. And it is no use to put a
semaphore around lua_unref only; you must do a mutex around all data shared
by lua_unref and other Lua functions. This includes lots of places, so the
easiest way is to put a mutex around Lua (this is what lua_lock/lua_unlock
do). (Or else you can try to "convince" the thread that executes your Lua
code to call lua_unref itself.)

-- Roberto