Question: Develop a class called Buffer that holds a single integer value. The class has two public methods called read ( ) that returns the current

Develop a class called Buffer that holds a single integer value. The class has two public methods called read() that returns the current value of the buffer and write(k) that writes integer k to the buffer. A thread invoking read must wait for a value to be written to the buffer. Once the item in the buffer is read it is cleared to allow a writer thread write. If the buffer contains a value a writer thread must wait for the current value of the buffer to be read by another thread.
Implement using ReentrantLock and condition variables
try{//stay in tunnel for random period int t =(int)(Math.random()*5000); Thread.sleep(t+2000);
}
catch(InterruptedException e){} tunnel.leave();
}}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!