in reply to Re: Having Win32 Perl crashs using ithreads
in thread Having Win32 Perl crashs using ithreads

Thank you *SO* much Mario!
I have been heads down digging through perl internals trying to diagnose the crash and didn't see your response.

Works for me as well!
I might dig in still to see why it is leading to a crash after just 2 iterations without freeing the IOQueue objects, but it at least gets my project back on track again.

Thanks again!
Chad
  • Comment on Re^2: Having Win32 Perl crashs using ithreads

Replies are listed 'Best First'.
Re^3: Having Win32 Perl crashs using ithreads
by marioroy (Prior) on Feb 19, 2016 at 00:17 UTC

    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

      Thanks I added calls to my IOQueue close functions in the ProcOpen::close and also untied the variables as you suggested.

      Since I got around the crashes I have also replaced the temp files used for the process STDOUT/STDERR with pipes, so that simplifies some of the processing (don't need to tail the files, can just read from the pipe until it closes). All seems well with it.

      Here is the "final" module if anyone is interested.

        I like your update with the CLOSE method. If by chance close is called twice at the application level, this will *not* raise an error. Nice ++

        sub CLOSE { $_[0] = {}; bless $_[0]; }