RW_Manager
private boolean busy;
public synchronized void start_read(){
while(busy) try { wait(); } busy = true;// lock
monitor
}
public synchronized void end_read(){
busy = false; notify();
}
public synchronized void start_write(){
while(busy) try { wait(); } busy = true;
}
public synchronized void end_write(){
busy = false; notifyAll();
}
Binary_Semaphore
private boolean busy;
public synchronized void P(){
while(busy) try { wait(); }busy = true;
}
public synchronized void V(){
busy = false; notify();
}
Bounded_Buffer
private int capacity, cmax;
private boolean empyt, full;
Bounded_Buffer(int upperBound) {
Capacity=0; cmax = upperBound;
empyt=true; full=false;
}
public synchronized void Remove(){
while (capacity <= 0) wait(); capacity--; notifyAll();
//or notify()???
}
public synchronized void Deposit(){
while (capacity >= cmax) wait(); capacity++; notifyAll();//or
notify()???
}
Storage_Manager
private int count, cmin, cmax;
private Vector threadList;
Storage_Manager(int initCount) {cmin = 41; cmax = initCount;}
public synchronized void Request(int n){
while (count –n <= cmin)
do wait();
count = count – n;
if (count > cmin) notify();
// do we still need to do this???
}
public synchronized void Release(int n){
count := count + n;
notify(); // what to do???
}
Alarm_Clock
private int now;
Alarm_Clock() {
now = 0;
}
public synchronized void tick() {
now++;
notifyAll(); // what to do???
}
public synchronized void wakeme(int interval) {
int AlarmSetting;
AlarmSetting = now + interval;
while (now < AlarmSetting)
wait();
notify(); // do we still need to do this???
}
Threads
Input
(1) Print out menu:
D for display system state
I for insert job into buffer
(2) Process user command
If ‘D’, V() on Binary_Semaphore
If ‘I’, parse input, Deposit() on Input_Bounded_Buffer
with job name, execution_time, storage_request & entry_time
Output
Remove() on Output_Bounded_Buffer
Display_State
(1) P() on Binary_ Semaphore
(2) StartRead() on RW_Manager, display all state of all jobs, endRead()
on RW_Manager
Ticker
tick() on Alarm_Clock (How to ensure tick() is called periodically?)
Executer
(Number of executers initialized at startup of main())
(1) StartRead() on RW_Manager, check to see if anyone waiting for storage,
endRead() on RW_Manager (How to do this efficiently? Busy checking??
Starving writer???) ** Maybe add a binary semaphore, every executer
P() before removing job from Input_Bounded_Buffer; V() after executer has
updated job state and check to see if anyone else waiting…
(2) Remove() on Input_Bounded_Buffer
(3) startWrite() on RW_Manager, add new record with job entry_time
+ status(waiting), endWrite () on RW_Manager
(4) Request(n) on Storage_Manager
(5) startWrite() on RW_Manager, update record with job status(running)
+ storage_allocation_time, endWrite () on RW_Manager
(6) wakeme(execution_time) on Alarm_Clock
(7) Release(n) on Storage_Manager
(8) startWrite() on RW_Manager, remove record from system_state, endWrite
() on RW_Manager
(9) Deposit() on Output_Bounded_Buffer with job entry_time, storage_allocation_time,
termination_time