Hey all, sorry if this is a silly question in anyway, fairly new to perl. I'm using perl 5.8.8 and don't really have much freedom to upgrade to 5.10 -- I'm running under linux (a slightly customized fc 6 build; based on the 2.6.22.9 kernel
I'm in the undesirable position of putting a wrapper around a set of binaries (these are tests for racks(s) of equipment) that someone else has created in order to execute all of these binaries, parse the output, etc and provide a nice unified user view of the results.
I initally tried doing this with fork and pipe, but found that the performance of the pipes was fairly poor (i.e. stdout would get bogged down and some tests would fail due to timeouts). I have now moved to a thread / Thread::Queue implementation, and performance is much better, but every now and again (not all the time), as the main script exits, i get:orA thread exited while 2 threads were running.
or something along those lines (sometimes i get a segfault for good measure as well).A thread exited while 2 threads were running. panic: MUTEX_LOCK (22) [op.c:352] during global destruction.
then in the main script (thread 0), i sit around and pull on the queue.my $thread = async { my $tid = threads->tid(); my ( $out, $in ); chdir $wd or die "Can't cd to $wd: $!\n"; my $pid = open2( $out, $in, $cmd ); # die "$!\n"; print $in "$_\n" foreach (@input); close $in or warn "close of input: $! $?\n"; my $err = 0; while (<$out>) { chomp; $err = 1 if (/^thread failed/); $Q->enqueue("$tid:$uut:$test:$_"); last if ($err); } kill( 2, $pid ) if $err; close $out; $Q->enqueue("$tid:$uut:$test:ENDEND"); waitpid ($pid, 0); }; $thread->detach();
my $tcount = count of tests that are running. while (1) { if ( $Q->pending ) { $_ = $Q->dequeue; chomp; if (/ENDEND$/) { $done++; print "\t-->got $done/$t_count $_\n"; } last if ( $done == $t_count ); next if (/ENDEND$/); } }
So, i would have thought that since i only send myself the ENDEND message once the open2 is done, and i make sure that i match up all of the tests i started with an end each that I would be okay to exit from the main program cleanly, but this is not so....
is there anyway that i can explicitly kill the threads? reading around I see the suggestion from the CPAN Threads module that maybe one should just turn these warnings off, but that doesn't seem right...
Any thoughts or ideas on how i can more likely have clean exits every time around?
In reply to cleanly exiting threads by JoeKamel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |