#!/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";
}
In reply to Re^2: END block not excuting when thread interrupted
by iankorf
in thread END block not excuting when thread interrupted
by iankorf
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |