lua-users home
lua-l archive

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


On 10 January 2018 at 04:31, Dan Tull <dtull@adobe.com> wrote:

> > The change to support our sampling profiler was to add a counter to the
> > global part of the Lua state ...
> What you've described is what debug.sethook does!
> L->hookmask is an atomic value, which makes it safe to set from another thread.
Not quite.

I haven't looked at this in a long time, but IIRC one problem is that lua_sethook is
per state (coroutine/thread) but I needed one that was global so that it would stop
regardless of which coroutine is running.

As an aside, the per-state/coroutine nature of the hooking mechanism has been a
pain on more than one occasion and only rarely useful.

Even without the global vs per coroutine problem, given that except for the main state,
any coroutine could get garbage collected (leaving the state pointer dangling), so 
lua_sethook is not safe to call from an arbitrary other thread.

DT