new-envwith_gc
Last change
on this file since 42107b4 was
56de6b39,
checked in by Thierry Delisle <tdelisle@…>, 7 years ago
|
Updated java signal benchmarks more closely mirror cfa/uC++ benchmarks
|
-
Property mode set to
100644
|
File size:
779 bytes
|
Line | |
---|
1 | class Monitor { |
---|
2 | public static volatile Boolean go = false; |
---|
3 | } |
---|
4 | |
---|
5 | class Signaller extends Thread { |
---|
6 | Monitor m; |
---|
7 | Signaller(Monitor m) { |
---|
8 | this.m = m; |
---|
9 | } |
---|
10 | |
---|
11 | public void run() { |
---|
12 | Monitor.go = true; |
---|
13 | while( Monitor.go ) { |
---|
14 | synchronized(this.m) { |
---|
15 | this.m.notify(); |
---|
16 | } |
---|
17 | } |
---|
18 | } |
---|
19 | } |
---|
20 | |
---|
21 | public class JavaThread { |
---|
22 | public static void main(String[] args) throws InterruptedException { |
---|
23 | int NoOfTimes = 50000; |
---|
24 | Monitor m = new Monitor(); |
---|
25 | long start, end; |
---|
26 | Signaller s = new Signaller(m); |
---|
27 | synchronized(m) { |
---|
28 | s.start(); |
---|
29 | while( !Monitor.go ) { |
---|
30 | Thread.yield(); |
---|
31 | } |
---|
32 | start = System.nanoTime(); |
---|
33 | for(int i = 1; i <= NoOfTimes; i += 1) { |
---|
34 | m.wait(); |
---|
35 | } |
---|
36 | end = System.nanoTime(); |
---|
37 | } |
---|
38 | Monitor.go = false; |
---|
39 | s.join(); |
---|
40 | System.out.println( (end - start) / NoOfTimes); |
---|
41 | } |
---|
42 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.