lua-users home
lua-l archive

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



On 9 Oct 2006, at 17:55, Mike Pall wrote:

Hi,

David Burgess wrote:
Yes, but given that the hook function gets called a lot. I was
hoping to avoid the registry lookups and just access my counters
on the C side (seaside?).

Two solutions:

- Just call your hook function less often. Set the hook count to
  a high number (10000 or so). Your timeout is fatal, so it
  doesn't have to be precise, right? Ensure that none of the C
  functions delay execution unduly.

- Setup a POSIX timer or a Windows thread which waits on the
  timeout. Then in the timeout handler set the lua hook with a
  count of 1. This is safe, even from a signal handler or a
  different thread. It's also the fastest solution because the
  hook is not active during regular execution.

I don't see how lua_sethook is safe when used in two different threads.

L->hook and L->base are modified in dependent ways, for example, and no attempt is made to synchronise the updates. What if one is using an architecture with relaxed memory order?

I'm pretty sure that lua_sethook isn't safe when used in a signal handler either.

drj