source: benchmark/schedint/JavaThread.java@ 734014e

ADT arm-eh ast-experimental cleanup-dtors enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 734014e was bf71cfd, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Moved up many directories in source

  • Property mode set to 100644
File size: 779 bytes
RevLine 
[56de6b39]1class Monitor {
2 public static volatile Boolean go = false;
3}
[6aa537a4]4
[56de6b39]5class Signaller extends Thread {
6 Monitor m;
7 Signaller(Monitor m) {
8 this.m = m;
9 }
[6aa537a4]10
[56de6b39]11 public void run() {
12 Monitor.go = true;
13 while( Monitor.go ) {
14 synchronized(this.m) {
15 this.m.notify();
[6aa537a4]16 }
17 }
18 }
[56de6b39]19}
[6aa537a4]20
[56de6b39]21public class JavaThread {
[6aa537a4]22 public static void main(String[] args) throws InterruptedException {
23 int NoOfTimes = 50000;
[56de6b39]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();
[6aa537a4]37 }
[56de6b39]38 Monitor.go = false;
[6aa537a4]39 s.join();
40 System.out.println( (end - start) / NoOfTimes);
41 }
42}
Note: See TracBrowser for help on using the repository browser.