[Chicago-talk] alarm race condition question

Brian Katzung briank at kappacs.com
Wed Jul 6 08:48:06 PDT 2011


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.

   - Brian

On 2011-07-06 10:01, Sean Blanton wrote:
> Below is some sample code I came across in its entirety. I'm looking 
> for some clarification.
>
> There is a comment on the first statement after the eval, "race 
> condition protection". What exactly is the race condition its 
> referring to?
>
> #------------------------
>
> eval {
>
>     local $SIG{ALRM} = sub { die 'Timed Out'; };
>     alarm 3;
>     my $sock = IO::Socket::INET->new(
>
>         PeerAddr => inet_ntoa( gethostbyname($host) ),
>
>         PeerPort => 'whois',
>
>         Proto => 'tcp',
>
>         ## Timeout => ,
>
>     );
>
>     $sock->autoflush;
>     print $sock "$qry\015\012";
>     undef $/; $data = <$sock>; $/ = "\n";
>     alarm 0;
>
> };
>
> alarm 0; # race condition protection <<<*********
>
> return "Error: Timeout." if ( $@ && $@ =~ /Timed Out/ );
> return "Error: Eval corrupted: $@" if $@;
>
> #------------------------
>
> Thanks,
> Sean
>
>
>
>
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk

-- 
Brian Katzung, Kappa Computer Solutions, LLC
Leveraging UNIX, GNU/Linux, open source, and custom
software solutions for business and beyond
Phone: 877.367.8837 x1  http://www.kappacs.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20110706/48465dc9/attachment.html>


More information about the Chicago-talk mailing list