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"; #### 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: 0x2018414 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: 0x22bf014 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: 0x3afc294 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: 0x3d65314 at C:\Documents and Settings\Peter\My Documents\PerlScratch\noname.pl line 25. Thread threads=SCALAR(0x201f80c) joined!