Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Hanging Threads

by BrowserUk (Patriarch)
on Aug 18, 2007 at 12:06 UTC ( [id://633469] : note . print w/replies, xml ) Need Help??


in reply to Hanging Threads

Your code as is, but with the Net::SMTP stuff commented out and replaced by a couple of sleeps, functions perfectly. Ie. The threads start, read the work items off the queue, terminate their loops and exit. And the joins all complete successfully and cleanly. Under 5.8.6 and 5.8.8.

So, maybe Net::SMTP isn't thread safe? Try starting one thread and see if that completes successfully?

If one works, try starting 2.

If you post again, properly indented code would be good.


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.

Replies are listed 'Best First'.
Re^2: Hanging Threads
by WalkingZero (Sexton) on Aug 18, 2007 at 20:38 UTC
    I found the problem(s). My issue kept getting complicated by the fact that the way I'd fix one issue would cause another. Something in my loop structure before was originally causing the issue. So when I used the 'self' function to test for loop exit, it helped me fix my loop. The ->self function though appears to have been what was locking the threads and preventing them from rejoining. Once I removed those two lines, I was golden.
      The ->self function though appears to have been what was locking the threads and preventing them from rejoining.

      Intriguing. Could you try putting those two lines back, but changing

      my $threadid = threads->self:

      to

      my $threadid = threads->self->tid;

      And report back what happens.

      FYI. threads->self() returns the thread's object reference, threads->self->tid() returns the thread's numeric identifier.

      I'm not aware that it would make a difference, but there is the possibility of some kind of circular reference prevent cleanup?

      If the above change 'cures' the problem, it might be a bug worth reporting. That said, I couldn't make it happen in either of the builds I have available. Which version of threads are you using? Eg.

      perl -mthreads -le"print $threads::VERSION" 1.62

      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.
        That did correct the issue, so something with that reference is causing the issue. Is it possible that when the ->self function is called it's creating a lock on that memory space? I tried running the command you asked for the threads version, it doesn't produce any output. Thoughts on that one?