Edit: Ignore all of this, it looks like BrowserUK figured it out just above...
in reply to Solaris + UltraSparc T2 + Threads: Avoid LCK's
I don't have a sufficiently recent threaded perl build around to test this theory, but I'd look at that assignment to $tmp in the inner loop in test2.
What happens if you just copy the int(rand(10)) into the inner loop without an assignment?
Of course, if this turns out to be the answer, WHY an assignment to a thread-local variable would cause that is a different question...