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

In reply to Solaris + UltraSparc T2 + Threads: Avoid LCK's by gulden

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.