Hello Monks,

I am back again with another "funny" behaviour of ActivePerl. I am using v5.12.2 on Windows 2008 SP1.

I want to read from a long-running co-process, and I want to be able to interrupt that procedure. In the meantime I want to calculate something asyncronously in a thread, but this thread should not be interruptible to join it in the end.

This code crashes my Perl interpreter:

#! /usr/bin/perl -w use strict; use threads; # Starting a co-process to read from. my $procid = open(READ, '-|', 'perl -e "$|=1; $SIG{INT} = \'IGNORE\'; +for ($i=0;$i<10;$i++) {print \"Line $i\n\"; sleep 1;}"'); my $break = 0; $SIG{INT} = sub { $break=1; }; sub calculation { local $SIG{INT} = 'IGNORE'; print("calculating somet +hing\n"); 5; } my $thread = async(\&calculation); # Reading from co-process. until ($break) { my $line = <READ>; last unless defined $line; print $line; } if ($break) { kill('ABRT', $procid); } close(READ); print $thread->join() ."\n";

Earlier you gave me the advice, not to use signals on Windows heavily, because they cannot be expected to work in all situations.

However, I think it is unbelievable that correct code can crash the interpreter. And, btw, the code is working properly whithout the thread. Can anybody explain?

----------

Thanks for your helping answers. I think BrowserUk gave the correct hint.


In reply to Correct code crashes ActivePerl Interpreter by heiermann

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.