Hello Monks,
I do not understand the behavior of threads, and prevent them coming into LOCK state.
I did two tests, in which the only difference is that one has an inner loop. I wanted to understand why the test with the Inner Loop (Test2) put the CPU USER state at 100% and without this inner loop, the threads are being LOCKED (see column of LCK PRSTAT).
Test1:
#!/opt/coolstack/bin/perl
use strict;
use threads ('yield',
'stack_size' => 64*4096,
'exit' => 'threads_only',
'stringify');
my $nloaders = 64;
#---------------------------------------------------------------
my @thrs_loaders;
for(1..$nloaders){
print "START LOAD $_ \n";
my ($thr) = threads->create(\&load, $_);
push @thrs_loaders ,$thr;
}
$_->join for @thrs_loaders;
print "STOP: " . localtime() . "\n";
exit;
#---------------------------------------------------------------------
+---------
sub load{
my $id = shift;
my $tmp;
for(1..7235617){
int( rand (10));
}
print "$id>LOAD EXIT\n";
}
PRSTAT for Test1:
PID USERNAME USR SYS TRP TFL DFL LCK SLP LAT VCX ICX SCL SIG PROCESS/LWPID
19883 mgarcia 100 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 24 3 0 perl/43
19883 mgarcia 100 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 28 2 0 perl/34
19883 mgarcia 100 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 26 3 0 perl/63
19883 mgarcia 100 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 26 3 0 perl/62
19883 mgarcia 100 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 26 3 0 perl/61
19883 mgarcia 100 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 23 3 0 perl/51
19883 mgarcia 100 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 29 3 0 perl/58
19883 mgarcia 100 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 35 3 0 perl/57
19883 mgarcia 100 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 35 3 0 perl/56
19883 mgarcia 100 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 35 3 0 perl/45
19883 mgarcia 100 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 33 2 0 perl/31
19883 mgarcia 100 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 35 2 0 perl/19
19883 mgarcia 100 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 37 3 0 perl/50
19883 mgarcia 100 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 36 3 0 perl/41
19883 mgarcia 100 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 37 2 0 perl/36
Test2:
#---------------------------------------------------------------------
+---------
sub load{
my $id = shift;
my $tmp;
for(1..7235617){
for(1..100000){
$tmp = $_;
}
int( rand (10));
}
print "$id>LOAD EXIT\n";
}
PRSTAT for Test2:
PID USERNAME USR SYS TRP TFL DFL LCK SLP LAT VCX ICX SCL SIG PROCESS/LWPID
19894 mgarcia 60 0.1 0.0 0.0 0.0 40 0.0 0.0 22 20 36 0 perl/19
19894 mgarcia 58 0.1 0.0 0.0 0.0 42 0.0 0.0 19 25 48 0 perl/56
19894 mgarcia 57 0.0 0.0 0.0 0.0 43 0.0 0.0 21 20 41 0 perl/32
19894 mgarcia 56 0.1 0.0 0.0 0.0 44 0.0 0.0 19 18 31 0 perl/23
19894 mgarcia 50 0.1 0.0 0.0 0.0 50 0.0 0.0 19 20 52 0 perl/25
19894 mgarcia 50 0.1 0.0 0.0 0.0 50 0.0 0.0 18 20 54 0 perl/33
19894 mgarcia 34 0.1 0.0 0.0 0.0 66 0.0 0.0 17 12 47 0 perl/34
19894 mgarcia 32 0.1 0.0 0.0 0.0 68 0.0 0.0 19 13 53 0 perl/10
19894 mgarcia 30 0.1 0.0 0.0 0.0 70 0.0 0.0 22 14 43 0 perl/15
19894 mgarcia 25 0.0 0.0 0.0 0.0 75 0.0 0.0 21 14 36 0 perl/65
19894 mgarcia 23 0.1 0.0 0.0 0.0 77 0.0 0.0 20 12 42 0 perl/4
19894 mgarcia 22 0.1 0.0 0.0 0.0 77 0.0 0.0 21 10 47 0 perl/9
19894 mgarcia 18 0.1 0.0 0.0 0.0 81 0.0 0.0 24 12 63 0 perl/22
19894 mgarcia 18 0.1 0.0 0.0 0.0 82 0.0 0.0 20 11 51 0 perl/55