|
On 2018-01-11 02:53 PM, Dan Tull wrote:
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 stopregardless of which coroutine is running.As an aside, the per-state/coroutine nature of the hooking mechanism has been apain on more than one occasion and only rarely useful.
I've had the complete opposite experience. The per-coroutine nature of hooking has been useful more than a pain. LuaJIT's variant has been a pain on more than one occasion for me. It's much easier (and more performant) to emulate LuaJIT's hook mechanism than it is to emulate Lua's.
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), solua_sethook is not safe to call from an arbitrary other thread. DT
-- Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.