1 6 7 package fr.emn.info.eaop.aspect; 8 9 import fr.emn.info.eaop.Monitor; 10 11 import java.util.*; 12 import java.lang.reflect.*; 13 import java.io.*; 14 15 24 public abstract class Coroutining extends AspectS implements Runnable { 25 26 Thread thread; 27 28 public Coroutining(AspectS up) { 29 super(up); 30 this.thread = new Thread (this); 31 synchronized (this) { 32 this.thread.start(); 33 try { 34 this.wait(); 35 } catch (Exception e) { 36 System.out.println("bug in the coroutining code"); 37 e.printStackTrace(); 38 System.exit(0); 39 } 40 } 41 } 42 43 46 public void run() { 47 this.definition(); 48 this.done(); 50 } 51 52 56 public void go() { 57 Monitor.monitor.path.push(this); 58 this.swap(); 59 Monitor.monitor.path.pop(); 60 } 61 65 public void block() { this.swap(); 67 } 68 69 73 void swap() { 74 synchronized (this) { 75 this.notify(); 76 try { 77 this.wait(); 78 } catch (Exception e) { 79 System.out.println("bug in the coroutining code"); 80 e.printStackTrace(); 81 System.exit(0); 82 } 83 } 84 } 85 86 92 public void done() { 93 synchronized (this) { 94 this.notify(); 95 } 96 } 97 98 102 abstract public void definition(); 103 } 104 | Popular Tags |