[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Time constraint in Lua pattern functions
- From: Roberto Ierusalimschy <roberto@...>
- Date: Wed, 30 Mar 2016 13:14:10 -0300
> 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