public void run() {
   while (true) {
     newInputSemaphore.release();
     if (terminated) break;
     process();
     newOutputSemaphore.take();
   }
 }
 public synchronized void terminate() { // Runs in other thread!
   terminated = true;
   newInputSemaphore.take();
 }
 public void proceed() { // This method will be run in the other thread!
   newInputSemaphore.take();
 }