<div>Right. I assume if you fork a bunch of processes and in those processes, alarm is called, that each one gets a separate alarm? It's process based in perl like the system call?</div><br clear="all">Regards,<br>Sean<br>
<br><br>
<br><br><div class="gmail_quote">On Wed, Jul 6, 2011 at 10:48 AM, Brian Katzung <span dir="ltr"><<a href="mailto:briank@kappacs.com">briank@kappacs.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div text="#000000" bgcolor="#FFFFFF">
I don't think I would call it a "race condition", but if the
IO::Socket dies for some other reason before the timeout, you
wouldn't want the alarm to still be pending.<br>
<br>
- Brian<div><div></div><div class="h5"><br>
<br>
On 2011-07-06 10:01, Sean Blanton wrote:
</div></div><blockquote type="cite"><div><div></div><div class="h5">
<div>Below is some sample code I came across in its entirety. I'm
looking for some clarification.</div>
<div><br>
</div>
<div>There is a comment on the first statement after the eval,
"race condition protection". What exactly is the race condition
its referring to?</div>
<div><br>
</div>
<div>
<div>#------------------------</div>
</div>
<div><br>
</div>
<div>eval { </div>
<blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div>local $SIG{ALRM} = sub { die 'Timed Out'; }; </div>
<div>alarm 3; </div>
<div>my $sock = IO::Socket::INET->new( </div>
</blockquote>
<blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div>PeerAddr => inet_ntoa( gethostbyname($host) ), </div>
</blockquote>
<blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div>PeerPort => 'whois', </div>
</blockquote>
<blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div>Proto => 'tcp', </div>
</blockquote>
<blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div>## Timeout => , </div>
</blockquote>
</blockquote>
<blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div>); </div>
<div><br>
</div>
<div>$sock->autoflush; </div>
<div>
print $sock "$qry\015\012"; </div>
<div>undef $/; $data = <$sock>; $/ = "\n"; </div>
<div>alarm 0; </div>
</blockquote>
<div>}; </div>
<div><br>
</div>
<div>alarm 0; # race condition protection <<<*********</div>
<div><br>
</div>
<div>return "Error: Timeout." if ( $@ && $@ =~ /Timed Out/
); </div>
<div>return "Error: Eval corrupted: $@" if $@;</div>
<div><br>
</div>
<div>#------------------------</div>
<div><br>
</div>
Thanks,<br>
Sean<br>
<br>
<br>
<br>
<fieldset></fieldset>
<br>
</div></div><pre>_______________________________________________
Chicago-talk mailing list
<a href="mailto:Chicago-talk@pm.org" target="_blank">Chicago-talk@pm.org</a>
<a href="http://mail.pm.org/mailman/listinfo/chicago-talk" target="_blank">http://mail.pm.org/mailman/listinfo/chicago-talk</a></pre>
</blockquote>
<br><font color="#888888">
<pre cols="72">--
Brian Katzung, Kappa Computer Solutions, LLC
Leveraging UNIX, GNU/Linux, open source, and custom
software solutions for business and beyond
Phone: <a href="tel:877.367.8837%20x1" value="+18773678837" target="_blank">877.367.8837 x1</a> <a href="http://www.kappacs.com" target="_blank">http://www.kappacs.com</a></pre>
</font></div>
<br>_______________________________________________<br>
Chicago-talk mailing list<br>
<a href="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/chicago-talk" target="_blank">http://mail.pm.org/mailman/listinfo/chicago-talk</a><br></blockquote></div><br>