Changeset 56de6b39 for src/benchmark
- Timestamp:
- Nov 27, 2017, 4:17:12 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 8a78dd3
- Parents:
- a6d70cd
- Location:
- src/benchmark
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/benchmark/Makefile.am
ra6d70cd r56de6b39 165 165 signal-cfa1.run \ 166 166 signal-cfa2.run \ 167 signal-cfa4.run 167 signal-cfa4.run \ 168 signal-java_thread.run 168 169 169 170 signal-upp$(EXEEXT): -
src/benchmark/schedint/JavaThread.java
ra6d70cd r56de6b39 1 import java.util.concurrent.atomic.AtomicBoolean; 1 class Monitor { 2 public static volatile Boolean go = false; 3 } 2 4 3 public class JavaThread { 4 public synchronized void doWait () throws InterruptedException { this.wait (); } 5 public synchronized void doSignal() throws InterruptedException { this.notify(); } 5 class Signaller extends Thread { 6 Monitor m; 7 Signaller(Monitor m) { 8 this.m = m; 9 } 6 10 7 public static AtomicBoolean go = new AtomicBoolean( false ); 8 9 public static class Signaller extends Thread { 10 JavaThread j; 11 Signaller(JavaThread j) { 12 this.j = j; 13 } 14 15 public void run() { 16 go.set( true ); 17 try { 18 while( JavaThread.go.get() ) { 19 this.j.doSignal(); 20 } 21 } catch(InterruptedException trash) { 22 11 public void run() { 12 Monitor.go = true; 13 while( Monitor.go ) { 14 synchronized(this.m) { 15 this.m.notify(); 23 16 } 24 17 } 25 18 } 19 } 26 20 21 public class JavaThread { 27 22 public static void main(String[] args) throws InterruptedException { 28 23 int NoOfTimes = 50000; 29 JavaThread j = new JavaThread(); 30 Signaller s = new Signaller(j); 31 s.start(); 32 while( !JavaThread.go.get() ) { 33 Thread.yield(); 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(); 34 37 } 35 long start = System.nanoTime(); 36 for(int i = 1; i <= NoOfTimes; i += 1) { 37 j.doWait(); 38 } 39 long end = System.nanoTime(); 40 go.set( false ); 38 Monitor.go = false; 41 39 s.join(); 42 40 System.out.println( (end - start) / NoOfTimes);
Note: See TracChangeset
for help on using the changeset viewer.