ThreadTest17

Sources

Java Source

Pthread C source

Brief Description

The objects participating in the threads are just counters. Their inc methods are performed within either semaphore or turn-taking gates. The Java version of the basic object class looks like:
class Obj {
  int count = 0;
  Semaphore semaphore = new Semaphore(1);

  void inc() throws InterruptedException {
    semaphore.require();
    doInc();
    semaphore.provide();
  }

  synchronized void turn() throws InterruptedException {
    waitForTurn();
    doInc();
    giveUpTurn();
  }

  synchronized void doInc() {
    ++count;
  }

  // ...
}
Where the semaphores and the turn-taking methods are hand-built out of Java/pthread monitors. The main test loops just repeatedly call the inc and turn methods, respectively.

Results

Machine        1-CPU Ultra-1  2-CPU Ultra-2  6-CPU SS1000

JDK1.2b2/green

No sharing           8002         6338         10275  
All sharing          8222         6182         10334
Taking turns        28490        22718  

JDK1.2b2/native

No sharing           8060         3715          7119
All sharing        116881       183272        521828
Taking turns       147872       175356   

SunSoft1.1.4b/native

No sharing                       36885
All sharing                     191940
Taking turns                    156206

Pthreads (CL = 1)

No sharing           3406         2701          3800
All sharing          3435         2684          3787

PThreads (CL = 2)

No sharing           3409         2016          3934
All sharing         43777       108000        267686

    
Details:

Here are some additional results for NT contributed by David Holmes.

NT4 on a Pentium Pro 180:

Microsoft JVM Build 4.79.2339
  No sharing:   time =   968ms (923ns per iteration)
  All sharing:  time =   953ms (908ns per iteration)
  Taking turns: time = 34703ms (33095ns per iteration)

JDK 1.2 Beta 2
  No sharing:   time =  8687ms (8284ns per iteration)
  All sharing:  time = 77078ms (73507ns per iteration)
  Taking turns: time = 65078ms (62063ns per iteration)

JDK 1.1.5
  No sharing:   time =  4656ms (4440ns per iteration)
  All sharing:  time =  4641ms (4426ns per iteration)
  Taking turns: time = 52750ms (50306ns per iteration)

Doug Lea
Last modified: Thu Jan 8 10:14:56 EST 1998