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.
In reply to Re^5: Thread weirdness
by BrowserUk
in thread Thread weirdness
by j0nny
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |