#!/usr/bin/perl use warnings; use strict; use threads; my $count = 0; # load a mem intensive thread first, then watch how mem drops # notice the difference in memory reclamation( top) after # the following thread is run with heavy,medium, light mem # on my machine # heavy mem use will skyrocket to 75%, then drop to 2% # medium will jump to 40% then drop to 20% # light use will jump to 5% then stay there # none use will stay at .3 % #my $t = threads->new(\&do_my_thing, $count, 1000000); #light #my $t = threads->new(\&do_my_thing, $count, 4000000); #medium my $t = threads->new(\&do_my_thing, $count, 8000000); #heavy #my $t = threads->new(\&do_my_thing, $count, 1); #none $t->join; select(undef,undef,undef,.1); while (1) { $count++; print "thread $count started\n"; my $t = threads->new(\&do_my_thing, $count, 1 ); $t->join; select(undef,undef,undef,.1); } <>; #wait for keypress to end, to check top sub do_my_thing { my ($val,$cdown) = @_; my %hash; for(0..$cdown){ $hash{$_} = 'a'; } select(undef,undef,undef,.1); print "thread $val ended\n"; }