This assignment makes use of the files contained in this zip file. This assignment is due Thursday, April 7.
This assignment is based on the bounded-bufer.zip examples that we used in class.
This assignment has three parts.
In the zip file there is the file Buffer.java
which implements a simulation of a first-in-first-out buffer. This simulated buffer doesn't really hold any data, it just keeps track of how many entries there are in the buffer and it prints a representation of the buffer to stdout every time an item is "put in" or "removed from" the buffer. This buffer is not thread safe; it is not synchronized in any way. If multiple threads access this buffer concurrently, then this buffer will become corrupted.
In the zip file there is a file Buffer_Bounded.java
which subclasses Buffer.java
and uses a lock and two condition variables to implement a bounded buffer. This is the example that we created in class in bounded-bufer.zip.
In the zip file there are files ProducersConsumers_v1.java
, Producer_v1.java
, and Consumer_v1.java
that are a producer/consumer simulation with three bounded buffers, two producers and one consumer. Each producer thread is in an endless loop where it randomly chooses one of the three buffers, puts an "item" into the buffer, and then displays the contents of the buffer in the console window. The consumer thread is in an endless loop where it randomly chooses one of the three buffers, takes an "item" from the buffer, and then displays the contents of the buffer in the console window. This simulation is prone to deadlock. The first part of this assignment is for you to write an explanation file, Deadlock_explanation.txt
, of how and why this simulation can end up deadlocked. Also answer these questions: if there is only a single producer and a single consumer but multiple buffers, can there be a deadlock? What if there are multiple producers and multiple consumers but only one buffer, can there be a deadlock?
In the zip file there are files ProducersConsumers_v2.java
, Producer_v2.java
, and Consumer_v2.java
that you are to complete so that they implement a producer/consumer simulation with three (unsynchronized) buffers, two producers, one consumer, and no deadlocks. The comments in those files outline how you are to prevent deadlocks.
For the third part of this assignment, in the zip file there are files ProducersConsumers_v3.java
, Producer_v3.java
, Consumer_v3.java
, and Buffer_TimeOut.java
that you are to complete so that they implement another producer/consumer simulation with three buffers, two producers, one consumer, and no deadlocks. This time, you will subclass Buffer.java
with the class Buffer_TimeOut.java
that has timed put()
and get()
methods. Implement the timed put()
and get()
methods using the timed await() method. Each Producer_v3
and Consumer_v3
determines the amount of time to wait before a timeout occurs. Use a 200 millisecond wait time.
Turn in a zip file called CS51590Hw1Surname.zip
(where Surname
is your last name) containing your versions of Deadlock_explanation.txt
, Producer_v2.java
, Consumer_v2.java
, Producer_v3.java
, Consumer_v3.java
, and Buffer_TimeOut.java
.
This assignment is due Thursday, April 7.