CIS481: Parallel and Distributed Software Systems

Assignment 3



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.



General Remarks:
1. Solve each problem. In the top of the first page  provide your name, SN, course number, and assignment number.
2. Provide all your reasoning and not only final answer.
3. Solutions are expected to be results of individual work.
4. Assignments are to be handed in the class (a hardcopy typed in using a wordprocessor including a typescript file showing sources, compilation and a sample running; or a hardcopy without typescript file plus source files should be emailed to TA if you did not include the script file with your hardcopy) on the due date specified on the assignment.
5. No late assignments will be accepted.


Lecture Materials Assignments Code