in reply to Re^2: Having Win32 Perl crashs using ithreads
in thread Having Win32 Perl crashs using ithreads
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Having Win32 Perl crashs using ithreads
by dchidelf (Novice) on Feb 19, 2016 at 18:06 UTC | |
by marioroy (Prior) on Feb 19, 2016 at 22:14 UTC |