in reply to Re: Re: Re: thread:shared
in thread thread:shared

(I think I've allready posted a reply, but I can't see it, so here's my second try).
The line in the Reader's loop:
next if ($NoClient < 2)
directly corresponds to my wish (and purpose) not to echo the input back to the Client: If only 1 Client is connected, there is nothing to send, so don't push anything into @chat.

But you can delete this line without any side effect - I think. If this line is deleted the input is pushed into @chat. Then the Writer tries to sent those lines but won't because he is not allowed to do
print $socket .. if ($1 ne $ID ..);
after that he is eliminating them from @chat. Just to prevent the Writer to do this for nothing I added the a.m. line.

Writer-Zombie
When the socket broke the Reader pushes his kill-code into @chat no matter how many Clients are left and on this the Writer is asked to work (cond_wait) and will find his 'personal' kill-code and he'll die.
As soon as I moved the 'kill-code-detection' from the wile (1) loop
-- formally I had: while ( "@chat" !~ ($ID\s$kill/){..
this place is after cond_wait and after the elimination of sent lines --
rigth after the cond_wait, I have had no more zombies. I pretty much convinced that this was the cause for this problem.

The memory access error I had went away as soon as I removed my bug splitting the empty $Elm. It could be that this is a mistake either of Perl or thread (thread:shared) or even Linux. It would be ok if the program crashes, but not in that way - I think.

I wish you and your relatives nice christmas days
here in Vienna we might get snow the next days, you too,
Carl

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: thread:shared
by zentara (Cardinal) on Dec 21, 2003 at 14:22 UTC
    Merry Christmas to you too. :-) Thanks for the explanations. The only problem I'm still seeing in my testing is that zombie thread. What happens for me depends on my testing. I'm starting the server, then connect with 3 clients. If I disconnect the clients, in the creation order, 1..2..3, first kill 1, then 2 then 3, there is no zombie thread left. But if I kill them off 3..2..1, then there is the zombie thread, and the server will crash when I restart the clients and send a message. I tried to not detach the $r and $w, and this problem goes away, the threads dissapear from the socklist, but they are still leaking internally, and the tid count from threads->list starts to climb. And my current approach is to try to use your Elm to join threads when they are no longer active. It is departing from your method though. Anyways, thanks for posting this. I learned alot.