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";