source: benchmark/schedint/JavaThread.java @ ff1e0f38

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprno_listpersistent-indexerpthread-emulationqualifiedEnum
Last change on this file since ff1e0f38 was bf71cfd, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

Moved up many directories in source

  • Property mode set to 100644
File size: 779 bytes
Line 
1class Monitor {
2        public static volatile Boolean go = false;
3}
4
5class 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
21public 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.