[Chicago-talk] alarm race condition question
Sean Blanton
sean at blanton.com
Wed Jul 6 09:24:01 PDT 2011
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?
Regards,
Sean
On Wed, Jul 6, 2011 at 10:48 AM, Brian Katzung <briank at kappacs.com> wrote:
> 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 listChicago-talk at pm.orghttp://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
>
>
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20110706/ccb9a328/attachment.html>
More information about the Chicago-talk
mailing list