iankorf has asked for the wisdom of the Perl Monks concerning the following question:
My program defines an END block to clean up after the program ends or if the program is interrupted. The END block is not executed when workers are interrupted with ^C. This is Perl 5.8.6 on Mac/Linux. Here's a simplified code snippet with the same behavior.
#!/usr/bin/perl use strict; use warnings; use threads; use Thread::Queue; my $Q = new Thread::Queue; for (my $i = 0; $i < 10; $i++) {$Q->enqueue(int rand 6)} my @worker; for (my $i = 0; $i < 4; $i++) {$worker[$i] = threads->create(\&worker, $Q)} for (my $i = 0; $i < 4; $i++) {$worker[$i]->join} print STDERR "workers done\n"; sub worker { my ($q) = @_; my $tid = threads->tid; while ($q->pending) { my $job = $q->dequeue; print STDERR "processing sleep($job) in thread $tid\n"; sleep($job); } } END { print STDERR "END block executed\n"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: END block not excuting when thread interrupted
by starbolin (Hermit) on Jul 09, 2006 at 06:28 UTC | |
Re: END block not excuting when thread interrupted
by HuckinFappy (Pilgrim) on Jul 09, 2006 at 03:05 UTC | |
Re: END block not excuting when thread interrupted
by jdhedden (Deacon) on Jul 09, 2006 at 17:31 UTC | |
by iankorf (Acolyte) on Jul 09, 2006 at 22:28 UTC | |
by BrowserUk (Patriarch) on Jul 10, 2006 at 00:09 UTC | |
Re: END block not excuting when thread interrupted
by jrockway (Acolyte) on Jul 09, 2006 at 23:33 UTC | |
by iankorf (Acolyte) on Jul 10, 2006 at 01:19 UTC |
Back to
Seekers of Perl Wisdom