lua-users home
lua-l archive

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


On 1 February 2012 21:56, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
>
> I use lua_sethook in luaposix inside a signal handler, in order to
> implement Lua signal handlers. Is there a safer way to achieve this?

As that message says, sethook is not "theoretically" safe. However, the
only problem seems to be the non-atomicity of pointer accesses. So,
it should be safe given the extra condition that read/write of pointer
addresses are atomic (which I believe is true on most machines).

It would be good if this (and any other necessary assumptions) could be documented. Preferably in the manual, but at least in the code.

(The problem is that, while reading the hook address, a signal
may change that adrress. Without  atomicity, the read may result
in a value that is neither the original nor the new value.)

I would say that, for practical purposes, the function is safe,
but no standard ensures that.

And of course there's also the issue of what happens when lua_sethook is interrupted by another call of itself. Not something that you need tackle, but worth documenting, just for those of us who thought it might be easy!

--
http://rrt.sc3d.org