Hello dchidelf,

The following is helpful if wanting the ProcOpen module to free up the handles automatically. Basically, this becomes important when omitting the closing of $out and $err handles at the application level.

Save the $out and $err handles after construction inside the procopen method.

tie *OFH, "IOQueue", $obuff, $self; tie *EFH, "IOQueue", $ebuff, $self; $$out = $self->{'outh'} = \*OFH; $$err = $self->{'errh'} = \*EFH;

Inside the close method, *untie* the $out and $err handles prior to joining the threads associated with the handles.

if (! defined $self->{'rc'}) { ... my $inh = $self->{'inh'}; my $outh = $self->{'outh'}; my $errh = $self->{'errh'}; my $pid = $self->{'pid'}; print "About to close\n"; ... $self->{'rc'} = $rc; untie *{$outh}; untie *{$errh}; print "Join Threads $othr $ethr\n"; $othr->join(); print "part done\n"; print "Join Threads $othr $ethr\n"; $ethr->join(); print "Threads joined\n"; ...

Well, that works just as well. IMHO, leave the *CLOSE* method inside IOQueue in the event one chooses to close the handles at the application level.

The above changes makes ProcOpen resilient to applications omitting the closing of $out and $err handles.

Regards, Mario


In reply to Re^3: Having Win32 Perl crashs using ithreads by marioroy
in thread Having Win32 Perl crashs using ithreads by dchidelf

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.