[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Options for Asynchronous Callbacks
- From: "Thijs Schreijer" <thijs@...>
- Date: Tue, 27 Mar 2012 19:34:08 +0200
> On Behalf Of Peng Zhicheng
> Sent: dinsdag 27 maart 2012 16:22
> To: lua-l@lists.lua.org
> Subject: Re: Options for Asynchronous Callbacks
>
> As far as I know, the only safe way in Lua to fire asynchronous events
> is to set a debug hook in the asynchronous callback and
> wait the Lua VM call the debug hook at some safe time (i.e. at VM
> instruction boundaries, to ensure the consistent of the Lua state)..
> and you may do your work in the hook. because I found only
> `lua_sethook' can be called asynchronously.
>
I'm not sure what you mean by 'can be called asynchronously', but there is an important difference between posix and windows here. Posix handles signals by stopping the current thread from executing the application and directing that thread to the signal handler. Whereas windows will spawn a new thread upon a SIGINT signal: "SIGINT is not supported for any Win32 application. When a CTRL+C interrupt occurs, Win32 operating systems generate a new thread to specifically handle that interrupt. This can cause a single-thread application such as one in UNIX to become multithreaded, resulting in unexpected behavior." See http://msdn.microsoft.com/en-us/library/xdkz3x12.aspx
I assume that lua_sethook is then 'signal safe' (ANSI), but I doubt that it is 'thread safe' (non-ANSI).
Thijs