>
> 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!
--