Caveat: Most of the contents of this post will only relate to you if you are using Win32. (Although the first bit about not being able to send on a socket from one thread whilst another thread is attempting to read from it may also be true on *nix for blocking sockets?)

The problem is that your are trying to both read and write to $Sock concurrently from two threads:

In your main thread:

while(1){ $Line = <$Sock>;

And in your Web thread, several instances of: &send_msg($Channel,"WEB FUNCTION THREAD STARTED"); which becomes:

print $Sock "PRIVMSG $_[0] :$_[1]\r\n";

As your threads are blocking, the writes SendMsg() is blocked until the read in the main thread completes. (Ie. some input arrives).

One solution is to set your socket non-blocking. (If your using Win32 Super search for '0x8004667e' for the collective wisdom on Win32 non-blocking sockets). However, this has a fairly profound knock-on for the architecture of your app.

A better solution is to only enter a read state when you know that there is something to be read. Unfortunately, the Win32 API that permits this is not directly available from Perl. Even if you access it directly (via: Win32::API), obtaining the appropriate Win32 system handle required to use it, , from the Perl level sockets, is entirely non-trivial.


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.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^5: Thread weirdness by BrowserUk
in thread Thread weirdness by j0nny

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.