home *** CD-ROM | disk | FTP | other *** search
/ Java 1996 August / Java - Summer 1996.iso / rockridge / java / threads / classes / CubbyHole.java < prev    next >
Encoding:
Text File  |  1995-11-13  |  342 b   |  19 lines

  1. class CubbyHole {
  2.     private int seq;         // this is the condition variable.
  3.     private boolean available = false;
  4.  
  5.     public synchronized int get() {
  6.     while (available == false) {
  7.         wait();
  8.     }
  9.     available = false;
  10.     return seq;
  11.     }
  12.  
  13.     public synchronized void put(int value) {
  14.     seq = value;
  15.     available = true;
  16.     notify();
  17.     }
  18. }
  19.