[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: signal-safety of lua_sethook
- From: Roberto Ierusalimschy <roberto@...>
- Date: Wed, 1 Feb 2012 19:56:36 -0200
> What's the latest on this?
> http://lua-users.org/lists/lua-l/2006-10/msg00427.html suggests that
> lua_sethook is not, in fact, signal safe, contrary to the assertion in
> the source (which also mentions "asynchronous use"). The manual makes
> no guarantee at all.
> 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).
(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.