in reply to Re^3: Solaris + UltraSparc T2 + Threads: Avoid LCK's
in thread Solaris + UltraSparc T2 + Threads: Avoid LCK's

The problem its related with the random function, whenever I use it the LOCKs appears...

If that's the case, it sounds like your platform has a badly adapted rand function. I don't see any locking involved with the use of rand on my system.

Can we assume that we must avoid rand function whenever using threads?

That would be overkill. In any real workload, calls to rand will likely make up a mere fraction of the total workload, so any contention involved will also likely be minimal for real applications.

In general, drawing conclusions based on extreme testcases--like calling rand in a tight loop concurrrently on 64-threads--is silly. If you ever comeup with a real application that suffers unduly as a result of lock contention calling rand, then consider using an alternative rand implementation. But the likelyhood of you ever encoutering this as a real problem in real code is quite small.


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."
  • Comment on Re^4: Solaris + UltraSparc T2 + Threads: Avoid LCK's

Replies are listed 'Best First'.
Re^5: Solaris + UltraSparc T2 + Threads: Avoid LCK's
by gulden (Monk) on Apr 24, 2009 at 10:53 UTC
    I made new tests and still not understand what the real reason.

    Instead of rand I have used other expressions:

    my $line = qq|Calling-Station-Id = "#crnh-b|; for( 1 .. 7e6 ) { expr N }

    Expr 1 (LOCKs High)

    my ($key, $value) = split(/ = /, $line);

    Expr 2 (LOCKs High)

    $line =~ /^([^=]+)\s=\s(.+)$/o;

    Expr 3 (No LOCKs at all)

    my $idx = index $line, " = ", 1; my $key = substr($line, 1,$idx); my $value = substr($line,$idx + 3);
    What is wrong? my Perl, my SO? or I'm not thinking right?

      Sorry, but I don't think I can help you. In part, because you do not appear to be asking for help--just making (somewhat dubious) assertions.

      There doesn't seem to be any logic to your tests, nor any questions in your posts.

      Perl does, of necessity, use some internal locking when running threads. So what?


      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.
        In my multithreaded program I need to remove all the REGEX, in order to improve the performance of my perl script!!!

        Whenever I use REGEX, my bottleneck its not the IO, but instead the REGEX's. And this, IMHO is bad.

        With this post I only want to know were was the botleneck of my script, and you are confirming to me that the Perl threads implementation have some problems.

        In my multithreaded program I need to remove all the REGEX, in order to improve the performance of my perl script!!!

        Whenever I use REGEX, my bottleneck its not the IO but instead the REGEX's. And this, IMHO is bad.

        With this post I only want to know were was the bottleneck of my script, and you are confirming to me that the Perl threads implementation have some problems.