in reply to Re: END block not excuting when thread interrupted
in thread END block not excuting when thread interrupted
#!/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^3: END block not excuting when thread interrupted
by BrowserUk (Patriarch) on Jul 10, 2006 at 00:09 UTC |