lua-users home
lua-l archive

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


On 11/18/18, nobody <nobody+lua-list@afra-berlin.de> wrote:
> You might also (ab)use this to trigger bookkeeping tasks (once per GC
> cycle), if you have no better way to do that.  (A fixed "every $n
> invocations of a function" scheme might not work (it could fire _both_
> too rarely and too often, at different times), and in certain restricted
> situations (games etc.), this might be as good as it gets… but note that
> this is slightly racy – _any_ allocation can trigger a GC cycle, so
> protect your data structures / make sure you're not reading inconsistent
> state when triggered in the middle of some change.)

A workaround for this can be found in classical signal-handling
techniques: the GC action can set a flag to be checked elsewhere to
determine whether or not the bookkeeping needs to be done. Of course,
whether GC cycles are the right thing to count is a different
matter...