Uploaded by Isha Swamy

Homer Simpson Problem: Semaphore Synchronization Project

advertisement
Design and Programming Project Assignment 3
CSIS 3810
Problem Description
Homer Simpson has been twice cloned, so now the world must deal with three Homers
with insatiable appetites for donuts. In this problem there are four tasks: three Homers
(not quite identical) and a Donut Chef. Each of the Homer tasks will make a donut and
eat it. The items necessary to build a donut are: the cooked donut shell (the dough
shaped for a filled donut), filling, and sprinkles. Each Homer possesses one of the three
items in an infinite quantity (IE. one has donut shells, another has filling, and a third has
sprinkles).
The Donut Chef has an infinite supply of all three items necessary to build a donut. At
random, the Donut Chef places two different (of the three necessary) items on a table.
The Homer that has the third item, acquires the contents of the table, notifies the Chef,
then builds the donut and consumes it (a Homer must have all three items to build a
donut.) Each Homer may take a variable time to build and consume their masterpiece.
After the notification, the Donut Chef then places two different (of the three necessary)
items (at random) on the table, and the cycle continues.
Your job is to implement a solution that synchronizes the Homers and the Donut Chef in
a an application (represented in pseudo code) using semaphores such that a deadlock
or indefinite postponement will not occur.
Your solution to the Homer Simpson Problem must use the semaphore primitives
(acquire and release) available in Java to synchronize the Homers and Chef. The
Homers and Chef code must be based on the Java semaphore implementation and
must not use any other synchronization technique.
In your implementation, each Homer, as well as the Chef, are required to run as
separate threads. The Chef must use a random number sequence for the Chef’s
product distribution.
The finished assignment must include the following:
•
A detailed word document including an overview of your solution and descriptive
pseudo code describing your solution.
1
Download