lua-users home
lua-l archive

Re: interrupting coroutines (was Re: Local Variables)

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


It was thus said that the Great Roberto Ierusalimschy once stated:
> > > What is "gL" here?
> > 
> > lua_State *gL;
> > 
> > It's a C variable that is either global, or static to the file the
> > routines are defined in.
> 
> And where its value come from? (I thought the whole point of the
> discussion was how to access the *running* coroutine when a signal
> happens.)
 Could very well be. I have the following Lua code:
	process = require "org.conman.process"
	signal = require "org.conman.signal-posix" -- [1]
	function doit()
	 print("coroutine",coroutine.running())
	
	 signal.catch('xcpu',function(sig)
	 print("I have become bored!",coroutine.running())
	 os.exit(1)
	 end)
	 signal.catch('int',function(sig)
	 print("I am done with you!",coroutine.running())
	 os.exit(1)
	 end)
 
	 while true do
	 end
	end
	process.limits.hard.cpu = 3
	process.limits.soft.cpu = 2
Those last two lines limit the amount of time the script runs. At 2
seconds, the system will send SIGXCPU; at 3, SIGKILL. If I then have the
script do:
	doit()
the script outputs:
	coroutine nil
	I have become bored! nil
and yet, if I do:
	coroutine.resume(coroutine.create(function() doit() end))
	coroutine thread: 0x23b1030
	Killed
which means SIGKILL was sent. It's obvious that SIGXCPU was caught, but it
didn't run (or rather, something happened when I attempted to run the
registered Lua function). Moving the signal.catch() calls out of the
function has the same results.
 -spc (Hmm ... perplexing ... )
[1]	https://github.com/spc476/lua-conmanorg/blob/master/src/signal-posix.c

AltStyle によって変換されたページ (->オリジナル) /