[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: signal-safety of lua_sethook
- From: Reuben Thomas <rrt@...>
- Date: Thu, 2 Feb 2012 11:44:38 +0000
On 1 February 2012 21:56, Roberto Ierusalimschy <firstname.lastname@example.org> wrote:
As that message says, sethook is not "theoretically" safe. However, the
> 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?
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!