Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: END block not excuting when thread interrupted

by BrowserUk (Patriarch)
on Jul 10, 2006 at 00:09 UTC ( #560037=note: print w/replies, xml ) Need Help??


in reply to Re^2: END block not excuting when thread interrupted
in thread END block not excuting when thread interrupted

Try this.

#!/usr/bin/perl use strict; use warnings; use threads; use Thread::Queue; $SIG{ INT } = sub{ print "Interupted\n"; exit; }; 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"; } __END__ c:\test>560021.pl processing sleep(0) in thread 1 processing sleep(4) in thread 1 processing sleep(1) in thread 2 processing sleep(0) in thread 3 processing sleep(1) in thread 3 processing sleep(4) in thread 4 processing sleep(3) in thread 2 processing sleep(5) in thread 3 processing sleep(3) in thread 1 processing sleep(2) in thread 2 Interupted END block executed

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://560037]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2023-01-31 22:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?