Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Hanging Threads

by GrandFather (Saint)
on Aug 18, 2007 at 05:38 UTC ( [id://633432] : note . print w/replies, xml ) Need Help??


in reply to Hanging Threads

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

Replies are listed 'Best First'.
Re^2: Hanging Threads
by BrowserUk (Patriarch) on Aug 18, 2007 at 12:08 UTC

    FYI: new() is an alias for create() in threads.

    Also, I don't see any of the unreferenced scalar errors when I run the OPs code?

    Update: I don't see the unreferenced scalar errors when I run your version either, so this appears to be a problem with your setup.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.