in reply to Re: Is this a bug of perl threads?
in thread SOLVED: Is this a bug of perl threads?

WOOOOOW, That's awesome! You are right!

Thank you almut, and thanks everybody, that problem was solved with handling $SIG{PIPE}.

Seems I need going to read some papers about signals.

Replies are listed 'Best First'.
Re^3: Is this a bug of perl threads?
by ikegami (Patriarch) on Mar 12, 2010 at 04:38 UTC
    That particular signal occurs when you attempt to write to a pipe or socket that's been disconnected. The default action is to kill the process. You can safely ignore the signal. In exchange, you should check if print succeeds, and exit the loop if not.
    sub server { local $SIG{PIPE} = 'IGNORE'; while (my $client = $server->accept()) { for my $sec (1..60) { sleep 1; print $client "$sec\n" or last; } } }