90 lines
No EOL
1.5 KiB
Text
90 lines
No EOL
1.5 KiB
Text
Monitor Bancone{
|
|
condition friggi;
|
|
condition pronti;
|
|
int nbomb = 0;
|
|
boolean butta = false;
|
|
|
|
public int friggi_i(){
|
|
if(nbomb > 0 and !butta)
|
|
wait(friggi);
|
|
return nbomb;
|
|
|
|
public void friggi_f(){
|
|
nbomb = 30;
|
|
butta = false;
|
|
}
|
|
|
|
public void servi_i(){
|
|
if(nbomb == 0)
|
|
wait(pronti);
|
|
}
|
|
|
|
public void servi_f(){
|
|
nbomb--;
|
|
if(nbomb == 0)
|
|
signal(friggi);
|
|
}
|
|
|
|
public void scaduti(){
|
|
butta = true;
|
|
signal(friggi);
|
|
}
|
|
}
|
|
|
|
Monitor Clock{
|
|
long tick = 0;
|
|
long alarm = -1;
|
|
condition sleeping;
|
|
|
|
public void wait_timer(){
|
|
if(alarm >= tick and alarm != -1)
|
|
wait(sleeping)
|
|
}
|
|
|
|
public void tick(){
|
|
tick++;
|
|
if(tick >= alarm and !empty sleeping)
|
|
signal(sleeping);
|
|
}
|
|
|
|
public void set_timer(long n){
|
|
alarm = tick + n;
|
|
}
|
|
}
|
|
|
|
Clock clock;
|
|
Bancone bancone;
|
|
|
|
Process Mario{
|
|
while(true){
|
|
int rimasti = bancone.friggi_i();
|
|
if(rimasti > 0) < butta >
|
|
< friggi i bomboloni >
|
|
bancone.friggi_f();
|
|
clock.set_timer(1 ora);
|
|
}
|
|
}
|
|
|
|
Process Piero{
|
|
while(true){
|
|
< attendi cliente >
|
|
bancone.servi_i();
|
|
< servi cliente >
|
|
bancone.servi_f();
|
|
}
|
|
}
|
|
|
|
Process Rosa{
|
|
while(true){
|
|
clock.wait_timer();
|
|
bancone.butta();
|
|
clock.set_timer(1 ora);
|
|
}
|
|
}
|
|
|
|
Process ClockRuns{
|
|
while(true){
|
|
< hardware tick >
|
|
clock.tick();
|
|
}
|
|
} |