lua-users home
lua-l archive

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


On Wed, Mar 30, 2016 at 9:14 AM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
>> However, lua_sethook is not documented to be free of the need to
>> synchronize. Looking at its code, setting a hook is definitely not a change
>> in a single atomic variable, so I wonder whether calling lua_sethook
>> without synchronization is truly portable
>
> The new version of 'lua_sethook' (not yet released :-) has the
> following explanation:
>
> /*
> ** This function can be called asynchronous (e.g. during a signal).
> ** Fields 'oldpc', 'basehookcount', and 'hookcount' (set by
> ** 'resethookcount') are for debug only, and it is no problem if they
> ** get arbitrary values (causes at most one wrong hook call). 'hookmask'
> ** is an atomic value. We assume that pointers are atomic too (e.g., gcc
> ** ensures that for all platforms where it runs). Moreover, 'hook' is
> ** always checked before being called (see 'luaD_hook').
> */
>
> So, if by "truly portable" you mean we can prove it is correct following
> the ANSI C documentation (which is our usual meaning, too), then you
> are right. But if we assume that "truly portable" means it will run
> correctly in any existing machine, than I guess that function is OK.
>
> (The type of 'hookmask' also changed from 'lu_byte' to 'l_signalT'
> in the [yet to be released :-)] new version; I don't know whether
> an access to 'char' can be non-atomic.)
>
> -- Roberto
>

Given that the code is not yet released, I can't inspect it myself. ;)
But are you using compiler intrinsic atomics when they're available?

/s/ Adam