in reply to threaded TCP server problem

my ($thr,$tid); ... while ((!($tid = threads->tid()))&&(my $client = $socket->accept)) { $thr = threads->create(\&process_request,$client);
Hmm, looks like there's a leak with detach. A workaround is to narrow the scope of $tid, ie
while ((!($tid = threads->tid()))&&(my $client = $socket->accept)) { my $thr = threads->create(\&process_request,$client);
otherwise when you re-enter the loop, the old value in $thr is still there, and gets cloned into the newly-created thread.

Dave.

Replies are listed 'Best First'.
Re^2: threaded TCP server problem
by Anonymous Monk on Mar 27, 2006 at 12:13 UTC
    Dave,
    Thank you. You have a good point.
    In the old situation, the script took 6/3 MB (VSZ/RSS) at startup.
    After 35 connects, the programme took 61/37 MB.
    With you fix, this went down to 34/6 MB (after 35 connects).