Hello again, I wanted to add a couple interesting observations I made today in trying to get this to work. I added a total hack to it. In the Debug() function, before doing the "print" statement, I added this in:
open(HACK, '|-'); close(HACK); .. and everything works fine. Now, why running a fork from within a thread would suddenly magically fix things (much like suspending and resuming) beats me. It's obvious something is hosed in the buffer. I've tried doing "select (STDOUT); $| = 1" and then doing "syswrites" and all kinds of low-level stuff to try and work around this but it's way beyond my area of expertise. -- ADAM MELTZER "Adam Meltzer" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > So, to revisit this. Still no luck, but I have made some interesting > observations. > > When running my app in debug mode, if I hit ^C to break, or set a > break-point, mysteriously everything begins working perfectly for the > thread. > > If I hit ^Z while the program is running, and then resume, that thread works > fine again too. However, if I try and talk to another thread, I have to ^Z > again and resume. > > This is just so weird and bizarre I'm not sure what the problem is. I have > attached the code that I am using, so if anyone has any input, please let me > know. The code itself is very simple, so it beats the hell out of me why > it's not working like it should. Obviously, it's some weird buffering issue, > but if it is, it's way too low-level for me. > > It's just driving me crazy because it's right at the point where I almost > have everything working, but this bites me, and blocks me until I can figure > it out. > > - Adam > > #!/usr/local/bin/perl -w > use strict; > use IO::Socket; > use threads; > use threads::shared; > my $sPort = '1692'; > my $debug = 1; > my %tstate : shared; > my $socket = new IO::Socket::INET ( > Type => SOCK_STREAM, > Proto => 'tcp', > Reuse => 1, > LocalPort => '1692', > Listen => 10, > ); > die("Could not open socket: $!") unless $socket; > > Debug("Creating the thread pool"); > createThreadPool(5); > Debug("Done!"); > > while (1) {} > > sub createThreadPool { > my ($threads) = @_; > for (my $i = 1; $i <= $threads; $i++) { > Debug("Creating server thread #$i"); > my $cmdbworker = > threads->create(sub{cmdbServerThread($socket)}) > ; > } > } > > sub cmdbServerThread { > my $tid = threads->tid; > { > lock(%tstate); > $tstate{$tid} = 'on'; > } > Debug("Starting thread $tid"); > my ($socket) = @_; > Debug("My socket is $socket"); > while($tstate{$tid} = 'on') { > while (my $server = $socket->accept()) { > print $server "HI!"; > while (my $conn = <$server>) { > Debug("Connection says: $conn"); > } > } > } > } > > sub Debug { > my ($message, $host) = @_; > my $tid = threads->tid(); > $tid = 'parent' if ($tid == 0); > my $time = time; > print STDOUT "[$tid$host] $time: $message\n"; > } > > -----Original Message----- > From: Adam Meltzer [mailto:[EMAIL PROTECTED] > Sent: Wednesday, June 25, 2003 9:57 AM > To: [EMAIL PROTECTED]; Arthur Bergman > Cc: [EMAIL PROTECTED] > Subject: Re: ithreads: printing to std* is acting very broken for me > > ----- Original Message ----- > From: "Arthur Bergman" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Cc: <[EMAIL PROTECTED]> > Sent: Wednesday, June 25, 2003 3:00 AM > Subject: Re: ithreads: printing to std* is acting very broken for me > > > Just one quick question, what happens when you turn off buffering and > > what platform are you using? > > > > Arthur > > > > Ah. I should have mentioned this. I've tried using both $|=0 and $|=1 and > neither appears to make any difference. Oh, and this is under Solaris 2. > Sorry for not mentioning this before. I do need to search through the rest > of the program's components and make sure that nothing is overriding this > setting. > > Is it possible also that there's a non-threadsafe module being invoked > somewhere in this application that's causing these issues? Most of the > modules that are being used aren't binary modules. DB_File is being used, > though. I wonder if that's causing any issues. > > - Adam >
