Topic: Monitors: Object-Based Synchronization
Points: 10
Assigned: September 9, 1999
Due: September 16, 1999



 

1. (3 points) What is a valid implementation of the Java notify operation required to guarantee about the selection of the thread that is unblocked. Consult the Java Language Specification.

2. (5 points) Solve the sleeping barber problem (see below) using CSP. Your solution must have a Barber process, a WaitingRoom process, and an array of Customer processes. In CSP, the notation
 
    Proc[i] (1..n) : [ code for process ]

can be used to define an array of processes each of which has a variable i whose value indicates it index among the n process. The notation Proc[j]?x and Proc[j]!x can be used to read from or write to, respectively, the process in the array whose index is given by the current value of j. Each Customer process should repeatedly seek haircuts. Assume there is a statement wait that delays the execution of the Customer for some period of time to simulate what the Customer does after getting a haircut or after finding all of the chairs full.

3. (2 points) Do problem 2.3 on page 44 of the text.
 
 

Sleeping Barber Problem:

A barber shop has one barber and n chairs for waiting customers, if any, to sit in. If there are no customers present, the barber waits for a customer to arrive. When a customer arrives, the customer receives a haircut from the barber. If additional customers arrive while the barber is cutting a customer's hair, they either sit down (if there are empty chairs) or leave the shop (if all chairs are full).