[Chicago-talk] alarm race condition question
Sean Blanton
sean at blanton.com
Wed Jul 6 08:01:51 PDT 2011
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20110706/63bc3dcc/attachment.html>
More information about the Chicago-talk
mailing list