Update: added Thread::Cancel solution.

I haven't used threads in perl (gotta try it sometime), but I'll take a wild stab at this....

okay, I've been playing with it, and determined that this is not a wild stab after all.

I noticed that you are using blocking I/O in your thread. $thread->join merely waits for the thread to terminate. I think the thread is blocking on I/O and thus not noticing that $die = 1.

As a quick fix, try sharing the thread's $sock variable, and adding close($sock) in your shutdown code (i.e. right after $die = 1;.) Basically, you have to find a way to wake up the thread from its I/O call. Another option is to send yourself a signal that is caught by the thread. Or, re-write your thread I/O to include a timeout so you can periodically check to see if it should exit.

I'm sure there are cleaner ways to do this. Like I said, I really should check out perl threads.

Update: The close($sock) probably won't work. If you don't care about cleanly shutting down the thread, just detach it and then call exit().

Update: Check out Thread::Cancel. It uses a signal to cancel threads. Very handy!


In reply to Re: IRC Client (non-bot) by pc88mxer
in thread IRC Client (non-bot) by deadpickle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.