in reply to second alarm(0)
Yep, it sure looks to me like any exceptions raised in the internal eval will go unnoticed. As for the second call to alarm, the authors explain
The second alarm 0 is in case the signal comes in after running the long-running operation, but before getting to the first alarm 0. If you don't do that, you would risk a tiny race condition—but size doesn't matter in race conditions; they either exist or they don't. And we prefer that they don't.The thing is, if the ALRM signal does arrive at that critical juncture the authors describe, what need is there for alarm 0 anymore? The ALRM already went off! The second alarm 0 would be necessary only if perl automatically reset the alarm interval back to its original value (in this case 5) whenever it received an ALRM signal, but this is not the case, at least not in my OS (Linux).
So I'll go out on a limb here, and have the temerity to correct the venerable TPC by rewriting the recipe's snippet like this:
I trust my fellow monks will let me know it if I am wrong.eval { local $SIG{ALRM} = sub {die "alarm here"}; alarm(5); eval { long_code(); }; alarm(0); die if $@; # propagate error } die if $@ && $@ !~ /alarm here/;
BTW, in the English edition of TPC, the alarm interval is set for 10 seconds. I guess Russians are more impatient. :-)
the lowliest monk
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: second alarm(0)
by powerman (Friar) on Apr 30, 2005 at 15:51 UTC | |
|
Re^2: second alarm(0)
by powerman (Friar) on Apr 30, 2005 at 15:41 UTC | |
by tlm (Prior) on Apr 30, 2005 at 16:06 UTC |