Loading ...
Sorry, an error occurred while loading the content.

Perl 5.8.4 bug? alarm + STDIN on Win32 == not working

Expand Messages
  • perlmedian
    well I installed 5.8.4 Perl and tried to use alarm on win32 with strange results. $SIG{ALRM} = sub { die Alarm! n }; alarm 2; my $ans = ; chomp($ans);
    Message 1 of 5 , May 4, 2004
    • 0 Attachment
      well I installed 5.8.4 Perl and tried to use alarm on win32 with
      strange results.

      $SIG{ALRM} = sub { die "Alarm!\n" };

      alarm 2;

      my $ans = <STDIN>;
      chomp($ans);

      print "No alarm.\n";

      The above DOES NOT work. but if you change the two lines after alarm
      2; to a sleep or something that takes more than 2 seconds you get the
      alarm.

      Is this a bug?

      Thx,
      Perl Median
    • Dave Gray
      ... You obviously haven t read the documentation for the alarm function: perldoc -f alarm
      Message 2 of 5 , May 4, 2004
      • 0 Attachment
        perlmedian wrote:
        > well I installed 5.8.4 Perl and tried to use alarm on win32 with
        > strange results.
        >
        > $SIG{ALRM} = sub { die "Alarm!\n" };
        >
        > alarm 2;
        >
        > my $ans = <STDIN>;
        > chomp($ans);
        >
        > print "No alarm.\n";
        >
        > The above DOES NOT work. but if you change the two lines after alarm
        > 2; to a sleep or something that takes more than 2 seconds you get the
        > alarm.
        >
        > Is this a bug?

        You obviously haven't read the documentation for the alarm function:

        perldoc -f alarm
      • perlmedian
        Obviously I have and tested the situation on my Solaris build of Perl 5.8.4. The code I supplied works as expected on Solaris Perl 5.8.4 but not on my Windows
        Message 3 of 5 , May 4, 2004
        • 0 Attachment
          Obviously I have and tested the situation on my Solaris build of Perl
          5.8.4. The code I supplied works as expected on Solaris Perl 5.8.4 but
          not on my Windows Perl 5.8.4 (both compiled from the same source
          code). I even attempted to use the eval/die pair with no success, and
          same results with Time::HiRes module.

          It seems that on Solaris, when <STDIN> is reached alarm keeps ticking.
          But for windows, when <STDIN> is reached alarm stops, then continues
          after the read from <STDIN>.

          Now, I would like some useful comments as to why the same code works
          differently on each OS.

          A good programmer: consults the docs, then his/her fellow programmers
          (offline), then web search, then posts to bulletin boards. I am
          posting on the bulletin board in the hopes that someone can correct me
          if it's a bug or not so I don't report erroneous bugs to the perlbug
          reports. It seemed like a bug to me, checked the docs, no info there
          about this behaviour, check with my collegues (they think it's strange
          behaviour) and checked the web, with no other info... hence I am here now.

          Thanks for your help,
          Perl Median (Nik)

          --- In perl-beginner@yahoogroups.com, Dave Gray <yahoogroups@d...> wrote:
          >
          > You obviously haven't read the documentation for the alarm function:
          >
          > perldoc -f alarm
        • Dave Gray
          ... Oh. I see what you re trying to do. My bad. That s not really a beginner question :) There are some useful hints here:
          Message 4 of 5 , May 4, 2004
          • 0 Attachment
            > Now, I would like some useful comments as to why the same code works
            > differently on each OS.

            Oh. I see what you're trying to do. My bad. That's not really a beginner
            question :)

            There are some useful hints here:
            <http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&c2coff=1&q=win32+%27%24SIG%7BALRM%7D%27&btnG=Search>
            Most of the links either directly say or make reference to the fact that
            Win32 doesn't support the alarm signal...

            And also if you run:
            perl -e "print qq^$_\n^ for keys %SIG"

            on Win32 ALRM isn't there. I'm not 100% sure what the significance of
            that is, but it *is* there on my linux box even without me defining one.
          • perlmedian
            ... Win32 does have alarm() in Perl 5.8 (or some strange emulation of it). What I am trying to find out is if it s a bug that alarm doesn t keep counting when
            Message 5 of 5 , May 4, 2004
            • 0 Attachment
              --- In perl-beginner@yahoogroups.com, Dave Gray <yahoogroups@d...> wrote:
              > Win32 doesn't support the alarm signal...
              >
              > And also if you run:
              > perl -e "print qq^$_\n^ for keys %SIG"
              >
              > on Win32 ALRM isn't there. I'm not 100% sure what the significance of
              > that is, but it *is* there on my linux box even without me defining one.

              Win32 does have alarm() in Perl 5.8 (or some strange emulation of it).
              What I am trying to find out is if it's a bug that alarm doesn't keep
              counting when waiting for STDIN. I don't know what the support
              is/going to be for alarm() on win32.

              You will see that alarm does work in the following code on Windows:

              $SIG{ALRM} = sub { die "Alarm!\n" };

              alarm 2;

              ## some really big loop that should take more than 2 seconds
              for ( 1 .. 2000000 ){
              for ( 1 .. 2000000 ){
              }
              }

              print "No alarm.\n";

              (see the parent post for the code that doesn't work)

              So I am wondering if it's something that needs fixing in CORE perl 5.8
              or if it's something that windows borks on its own.

              I see that others have reported bugs to this same problem, I added my
              info to one of those bugs:
              http://guest:guest@.../rt3/Ticket/Display.html?id=24892
            Your message has been successfully submitted and would be delivered to recipients shortly.