OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [testsuite/] [libjava.lang/] [SyncTest.java] - Blame information for rev 774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 765 jeremybenn
// Test atomic increment via synchronized blocks.
2
public class SyncTest implements Runnable {
3
  static int counter;
4
 
5
  public void run() {
6
    // We cache the .class value; otherwise this code is
7
    // slow enough that it will time out in some situations.
8
    Object lock = SyncTest.class;
9
    for (int n = 0; n < 1000000; n++)
10
      synchronized (lock) {
11
        counter++;
12
      }
13
  }
14
 
15
  public static void main(String[] args) {
16
    SyncTest test = new SyncTest();
17
    Thread[] thr = new Thread[4];
18
 
19
    for (int n = 0; n < thr.length; n++) {
20
      thr[n] = new Thread(test);
21
      thr[n].start();
22
    }
23
 
24
    for (int n = 0; n < thr.length; n++) {
25
      try {
26
        thr[n].join();
27
      } catch (InterruptedException ex) {
28
      }
29
    }
30
 
31
    System.out.println(counter == 1000000 * thr.length ?
32
      "ok" : "fail: " + counter);
33
  }
34
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.