CPAN::Forum
threads-shared - pls a little help, kind of howto..
| Posted on Tue Jun 19 17:51:11 2007 by calli |
| pls a little help, kind of howto.. |
|
Hi,
I have made a little program using an older version of threads and now it does not work properly..
So my little question what is wrong now?
1st thread is listening to my tcp-traffice (using NetPacket)
$q = "..";
and pushes this a)
{
lock($PIPS); # only for 2nd thread!!
$PIPS .= $q; #
}
and pushes it to a threaded chat-Array to send to any socket client that has been accepted:
{
lock(@chat); # push for sending to all
push @chat, $qtsID."\t".$q; # $qtsID is an identifier not to send back to origine
cond_signal(@chat);
}
2nd thread takes this to do s.th with it:
{
lock($PIPS);
$nPips = $PIPS;
$PIPS = '';
}
...
and pushes the result as well to the chat-Array..
{
lock(@chat);
push @chat;
cond_signal(@chat);
} # un-block vars block
Finally pairs of threads were created when aksed for a socket-connection.
The 'Reader' (here) just listens to know when to die:
while(defined ($l = <$socket>) ){ # empty loop }
{
lock($NoClient);
$NoClient--;
}
# if you want to kill the Writer immediately and not only after the next input: de-commet:
{
lock(@chat);
cond_broadcast(@chat);
}
and the 'Sender' after sending some files send those performs:
while( 1 ) {
lock(@chat);
cond_wait(@chat);# if (@chat);
next unless (@chat);
...
foreach (@chat) {
...
print $SOCKET ...
}
}
Well this has worked, but now - I think - it blocks everything
right after the first client has died...
Do I just have to put bracktes within while(1) ?
while( 1 ) {
{# add bracket open
lock(@chat);
cond_wait(@chat);
next unless (@chat);
...
foreach (@chat) {
...
print $SOCKET ...
}
} # add bracket close
}
Thanks in advance,
Carl
|
| Write a response |
(0)
]