lua-users home
lua-l archive

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


It was thus said that the Great William Ahern once stated:
> On Mon, Aug 11, 2014 at 09:55:40PM -0400, Sean Conner wrote:
> > It was thus said that the Great William Ahern once stated:
> <snip>
> > > >   Yeah, it's a bit of a round-about way of doing things, but it appears to
> > > > tbe the safest way of handling signals in Lua.  I've done two
> > > > implementations based on this method, on for ANSI-C only:
> > > 
> > > The safest way is to not handle signals asynchronously at all. 
> > 
> >   "The safest way is to not handle signals ------------- at all."
> > 
> >   Fixed that for you 8-P
> 
> sigtimedwait is both POSIX and completely safe. It clears the pending set
> atomically. And even without without sigtimedwait you can emulate it. I had
> a discussion about this in comp.unix.programmer a couple of years ago. There
> are several ways to do it, and at least one technique is nearly ANSI
> C-compatible (if you don't count use of nanosleep or sigset_t routines),
> async-signal-safe, and uses no global state.

  I do, so that's not ANSI-C.  It's POSIX.

  I also think that if a feature is so damn hard to use, perhaps it's time
to retire (with extreme prejudice) and do something else (but that's me---I
still feel signals are a horrible abstraction).

> >   But this won't handle the original problem:
> > 
> > 	coroutine.resume(coroutine.create(function() while true do end end))
> 
> Neither will using lua_sethook! IIRC this was discussed in another thread a
> few weeks ago. Here's the relevant code in Lua (from 5.2 source code):
> 
> LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count) {
>   if (func == NULL || mask == 0) {  /* turn off hooks? */
>     mask = 0;
>     func = NULL;
>   }
>   if (isLua(L->ci))
>     L->oldpc = L->ci->u.l.savedpc;
>   L->hook = func;
>   L->basehookcount = count;
>   resethookcount(L);
>   L->hookmask = cast_byte(mask);
>   return 1;
> }

  It diverts the flow of control within a coroutine, which is the point.  

> Note that it only sets the hook for the currently running coroutine.

  And the hook will gain control at the next possible point (since the code
n question hooks calls, returns and next VM instruction).  

  -spc