Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

BoundedBuffer.java

00001 class BoundedBuffer 
00002 {
00003      int tail;
00004      int head;
00005      int bound;
00006      
00007      public BoundedBuffer(int b)
00008      {
00009           this.bound = b;
00010           this.head = 0;
00011           this.tail = (this.bound - 1);
00012      }
00013      
00014      public synchronized void add ()
00015      {
00016           while (this.tail == this.head)
00017           {
00018                try {
00019                     this.wait();
00020                }
00021                catch (java.lang.InterruptedException ex) {
00022                }
00023           }
00024           this.head = ((this.head + 1) % this.bound);
00025           this.notifyAll();
00026      }
00027      
00028      public synchronized void take ()
00029      {
00030           while (this.isEmpty())
00031           {
00032                try {
00033                     this.wait();
00034                }
00035                catch (java.lang.InterruptedException ex) {
00036                }
00037           }
00038           this.tail = ((this.tail + 1) % this.bound);
00039           this.notifyAll();
00040           return;
00041      }
00042      
00043      public synchronized boolean isEmpty ()
00044      {
00045           return (this.head == ((this.tail + 1) % this.bound));
00046      }
00047 }

Generated at Thu Feb 7 06:41:08 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001