in reply to Solaris + UltraSparc T2 + Threads: Avoid LCK's

I'm not sure if any of this is helpful as I'm on a different platform and I'm not at all sure that anything I'm seeing will be applicable. When I run this version of your code here:

#! perl -sw use 5.010; use strict; use threads; $_->join for map { async { for( 1 .. 7e6 ) { int rand 10; } }; } 1 .. 64; say "Test 1 complete"; <STDIN>; $_->join for map { async { my $tmp; for ( 1 .. 7e6 ) { for ( 1 .. 1e5 ) { $tmp = $_; } int rand 10; } }; } 1 .. 64;

I do perceive a very slight drop in cpu sctivity between the first batch and the second.

The first nails the cpu counter at (or very close to) 75% (100% of 3 of 4 cpus--I have something running on the other cpu). What minor wobbles occur go no lower than 74.8; and it occasionally shows slightly greater than 75%--though that probably just the result of maths.

The second again gets close to 75%, but the wobbles are larger. It occasionally drops as far as 73% and rarely get as high as 74.8%. So something is preventing the second from maxing the cpu. I do not see any signs of locks, though I may not be instrumenting the right things. I need to look further into the measurements available--the list is very long. But in any case, the drop is nothing like as dramatic here, as your instrumentation appears to show on your platform!

Following anonymonks lead, I replaced (both) implicit loop counters with lexicals in the second batch:

for my $i ( 1 .. 7e6 ) { for my $j ( 1 .. 1e5 ) { $tmp = $j; }

And the drop in cpu utilization "went away", which does tend to indicate that it is somehow related to use of the global $_. Whilst that is global, it isn't shared, (I bleieve it is cloned on a per interpreter basis), so it shouldn't require internal locking. But globals do carry a small penalty over lexicals--regardless of the use of threads--so whether that has anything to do with it I am unsure. I can't see why it would, but I have considerable difficulty follwing the internals in areas that relate to cloning.

I'll try too look into it in more detail, but that will take a while.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."