Altering your code to run as a standalone sample without needing access to a mail server and using threads (hence create rather than new) I get:
use warnings;
use strict;
use threads;
use Thread::Queue;
sub smtpblast{
my $mdq= shift;
my $pending= $mdq->pending;
while ($pending > 0){
my $md= $mdq->dequeue_nb;
print "processing $md\n";
sleep $md;
$pending= $mdq->pending;
}
my $threadid = threads->self;
print "\n The process for thread $threadid is finished!\n";
}
my $mdqueue=Thread::Queue->new();
$mdqueue->enqueue(10, 2, 5, 3, 7, 5);
my $thr1=threads->create (\&smtpblast, $mdqueue);
my $thr2=threads->create (\&smtpblast, $mdqueue);
my $thr3=threads->create (\&smtpblast, $mdqueue);
my $thr4=threads->create (\&smtpblast, $mdqueue);
$thr1->join;
print "\n Thread $thr1 joined! \n";
$thr2->join;
print "\n Thread $thr2 joined! \n";
$thr3->join;
print "\n Thread $thr3 joined! \n";
$thr4->join;
print "\n Thread $thr4 joined! \n";
which prints:
processing 10
processing 2
processing 5
processing 3
processing 7
processing 5
The process for thread threads=SCALAR(0x3fdc57c) is finished!
The process for thread threads=SCALAR(0x4508800) is finished!
The process for thread threads=SCALAR(0x3ab0328) is finished!
The process for thread threads=SCALAR(0x2534bbc) is finished!
Attempt to free unreferenced scalar: SV 0x2023ed0, Perl interpreter: 0
+x2018414 at C:\Documents and Settings\Peter\My Documents\PerlScratch\
+noname.pl line 22.
Thread threads=SCALAR(0x201f7e8) joined!
Attempt to free unreferenced scalar: SV 0x22c2318, Perl interpreter: 0
+x22bf014 at C:\Documents and Settings\Peter\My Documents\PerlScratch\
+noname.pl line 23.
Thread threads=SCALAR(0x201f7f4) joined!
Attempt to free unreferenced scalar: SV 0x383cc50, Perl interpreter: 0
+x3afc294 at C:\Documents and Settings\Peter\My Documents\PerlScratch\
+noname.pl line 24.
Thread threads=SCALAR(0x201f800) joined!
Attempt to free unreferenced scalar: SV 0x3d68e68, Perl interpreter: 0
+x3d65314 at C:\Documents and Settings\Peter\My Documents\PerlScratch\
+noname.pl line 25.
Thread threads=SCALAR(0x201f80c) joined!
and terminates as expected despite the errors.
Can you generate a similar sample the demonstrates the problem you are seeing?
DWIM is Perl's answer to Gödel
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.