#!/usr/bin/perl -w use threads; use threads::shared; share $threadscount; $threadscount = 0; share $maxthreads; $maxthreads = 0; share $threadscreated; $threadscreated = 0; # Dump out virtual memory and resident memory consumption sub printmemorysizes{ open F, "; close F; my @vmsize = grep /^VmSize.*/, @s; chomp $vmsize[0]; print $vmsize[0], " "; my @rss = grep /^VmRSS/, @s; print $rss[0]; } # The treads' sub sub thread{ my $count; { lock $threadscount; $threadscount ++; # count how many threads there are $count = $threadscount; lock $maxthreads; if ( $count>$maxthreads ){ $maxthreads = $count; # Store the maximum of concurrent threads } lock $threadscreated; $threadscreated ++; } #print "threadscreated: $threadscreated "; #&printmemorysizes(); select undef,undef,undef,1; lock $threadscount; $threadscount --; } while ( 1 ){ for ( 1..300 ){ my $t = threads->create("thread"); $t->detach(); } my $tc; do { select undef,undef,undef,0.1; # SLEEP # as shorter the sleep the memory cunsumption raises faster it seems lock $threadscount; $tc = $threadscount; } while ( $tc ); #sleep 2; # dump out: #maximum concurrent threads | How many threads have been created | # virtual memory size | resident memory size print "maxthreads: $maxthreads threadscreated: $threadscreated "; printmemorysizes(); $maxthreads = 0; }