1. Monitors, based on pp.202, ex.4.36 (4 points)
The Bear and the Honeybees.Given are n honeybees and a hungry bear. They share a pot of honey. The pot is initially empty; its capacity is
H portions of honey. The bear sleeps until the pot is full, then eats all the honey and goes back to sleep. Each bee repeatedly gathers one
portion of honey and puts it in the pot; the bee who fills the pot awakes the bear. Represent the bear and honeybees as processes and develop a
solution of this problem using a monitor for synchronization. Use the Signal and Continue discipline.
2. Monitors and Semaphores, pp.256, ex.5.5 (4 points)
Consider the following definition of (counting) semaphores due to Habermann, 1972. Let na
be the number of times a process has attempted a P operation, let np be the number of
completed P operations, and let nv be the number of completed V
operations. The semaphore invariant for this representation is
np == min(na, nv)
This invariant specifies that a process delayed in a P operation should be
awakened and allowed to continue as soon as enough V operations have been executed.
(a) Develop a monitor that implements semaphores using this representation (i.e., np, na, nv)
and invariant. Use the Signal and Continue discipline.
(b) Develop a monitor that implements semaphores using this representation and invariant. Use the Signal and Wait
discipline.
For question (1) use Java under Red Hat Linux in D305 or under Windows (your choice). For question (2) you can write a
pseudocode.
Lecture Materials | Assignments | Code |