domani mcad please

This commit is contained in:
Francesco Mecca 2019-01-23 22:06:36 +01:00
parent 2e42d4cf4c
commit 00a7905f55
6 changed files with 416 additions and 95 deletions

View file

@ -0,0 +1,109 @@
monitor Vassoio{
int b = 0;
timer_scaduto = false;
condition servi;
condition friggi;
condition cliente;
public int servi(){
while(b == 0 || timer_scaduto || empty(cliente)){
wait(servi);
}
b--;
signal(cliente);
return b;
}
public int friggi(){
if(!(b == 0 && timer_scaduto))
wait(friggi);
return b;
}
public void riempi(){
b = 30;
timer_scaduto = false;
signal(servi);
}
public void butta(){
timer_scaduto = true;
signal(friggi);
}
public void ordina(){
signal(servi);
wait(cliente);
}
}
monitor Alarm{
int now = 0;
int alarm = -1;
condition waiting;
public void tick(){
now++;
if(alarm != -1 && alarm <= now){
alarm = -1;
signal(waiting);
}
}
public void waittimer(){
wait(waiting);
}
public void settimer(int s){
if(s == 0){
alarm = -1;
signal(waiting);
}
else
alarm = now + s;
}
}
Vassoio v;
Alarm a;
Process Mario{
int b;
while(true){
b = v.friggi();
if(b > 0)
<butta>;
<friggi>;
a.settimer(60);
v.riempi();
}
}
Process Piero{
int b;
while(true){
<aspetta cliente>;
b = v.servi();
<servi>;
if (b == 0)
a.settimer(0);
}
}
Process Rosa{
while(true){
a.waittimer();
v.butta();
}
}
Process Clock{
while(true){
<aspetta un secondo>;
a.tick();
}
}
Process Cliente{
v.ordina();
}

View file

@ -50,7 +50,6 @@ process Mario{
<friggi> <friggi>
setTimer(60); setTimer(60);
send(s) to p.rilascio_vassoio; send(s) to p.rilascio_vassoio;
} }
} }

View file

@ -30,7 +30,7 @@ Process Bancone {
[] tick >= alarm and alarm != -1; accept wait_timer() -> [] tick >= alarm and alarm != -1; accept wait_timer() ->
butta = true; butta = true;
nbomb = 0; nbomb = 0; // errore
alarm = -1; alarm = -1;
[] ; accept set_timer(in long n) -> [] ; accept set_timer(in long n) ->

View file

@ -1,93 +1,80 @@
monitor Vassoio{ monitor Vassoio{
int b = 0; int b = 0;
timer_scaduto = false; timer_scaduto = false;
condition servi; condition servi;
condition friggi; condition friggi;
public int servi(){
public int servi(){ if (b == 0 || timer_scaduto){
if (b == 0 || timer_scaduto){ wait(servi);
wait(servi); }
} servi --;
servi --; return b;
return b; }
} public int friggi(){
if(!(b == 0 && timer_scaduto))
public int friggi(){ wait(friggi);
if(!(b == 0 && timer_scaduto)) return b;
wait(friggi); }
return b; public void riempi(){
} b = 30;
timer_scaduto = false;
public void riempi(){ signal(servi);
b = 30; }
timer_scaduto = false; public void butta(){
signal(servi); timer_scaduto = true;
} signal(friggi);
}
public void butta(){ }
timer_scaduto = true; monitor Alarm{
signal(friggi); int now = 0;
} int alarm = -1;
} condition waiting;
public void tick(){
monitor Alarm{ now++;
int now = 0; if(alarm != -1 && alarm <= now){
int alarm = -1; alarm = -1;
condition waiting; signal(waiting);
}
public void tick(){ }
now++; public void waittimer(){
if(alarm != -1 && alarm <= now){ wait(waiting);
alarm = -1; }
signal(waiting); public void settimer(int s){
} alarm = now + s;
} }
}
public void waittimer(){ Vassoio v;
wait(waiting); Alarm a;
} Process Mario{
int b;
public void settimer(int s){ while(true){
alarm = now + s; b = v.friggi();
} if(b > 0)
} <butta>;
<friggi>;
Vassoio v; a.settimer(60);
Alarm a; v.riempi();
}
Process Mario{ }
int b; Process Piero{
while(true){ int b;
b = v.friggi(); while(true){
if(b > 0) <aspetta cliente>;
<butta>; b = v.servi();
<friggi>; <servi>;
a.settimer(60); if (b == 0)
v.riempi(); a.settimer(0);
} }
} }
Process Rosa{
Process Piero{ while(true){
int b; a.waittimer();
while(true){ v.butta();
<aspetta cliente>; }
b = v.servi(); }
<servi>; Process Clock{
if (b == 0) while(true){
a.settimer(0); <aspetta un secondo>;
} a.tick();
} }
}
Process Rosa{
while(true){
a.waittimer();
v.butta();
}
}
Process Clock{
while(true){
<aspetta un secondo>;
a.tick();
}
}

View file

@ -0,0 +1,112 @@
Process Rosa{
int nbomb = 0;
bool vaiMario = true;
signal s;
process p;
port signal friggi_i;
port signal friggi_f;
port signal servi_i;
port signal servi_f;
port signal segnalaMario;
do
* vaiMario == true; p = receive(s) from friggi_i; ->
vaiMario = false;
send(nbomb) to p.ok;
* ; p = receive(s) from friggi_f; ->
nbomb = 30;
* nbomb > 0 and !vaiMario; p = receive(s) from servi_i; ->
send(s) to p.ok;
* ; p = receive(s) from servi_f; ->
nbomb--;
send(nbomb) to p.rimasti;
* ; p = receive(s) from segnalaMario; ->
vaiMario = true;
od
}
Process Clock{
int now = 0;
int alarm = -1;
signal s;
process p;
do
* ; p = receive(s) from tick; ->
now++;
if(now >= alarm and alarm != -1){
alarm = -1;
send(s) to Rosa.segnalaMario;
}
* ; p = receive(n) from set_timer; ->
if(n == 0){
alarm = -1;
send(s) to Rosa.segnalaMario;
} else {
alarm = now + n;
}
od
}
Process Mario{
int nbomb = 0;
signal s;
port int ok;
while(true){
send(s) to Rosa.friggi_i;
p = receive(nbomb) from ok;
if(nbomb > 0){
< butta >
}
< friggi >
Clock.set_timer(60 minuti);
send(s) to Rosa.friggi_f;
}
}
Process Piero{
int nbomb = 0;
signal s;
port int rimasti;
port signal ok;
process p;
process cliente;
while(true){
client = receive(s) from nuovo_cliente;
send(s) to Rosa.servi_i;
p = receive(s) from ok;
< servi cliente >
send(s) to cliente.rilascio;
send(s) to Rosa.servi_f;
p = receive(nbomb) from rimasti;
if(rimasti == 0){
Clock.set_timer(0);
}
}
}
Process Cliente{
signal s;
port signal rilascio;
process p;
send(s) to Piero.nuovo_cliente;
p = receive(s) from rilascio;
< mangia >
< esci >
}
Process HWClock{
signal s;
while(true){
< hw tick >
send(s) to Clock.tick;
}
}

View file

@ -0,0 +1,114 @@
Monitor Bancone{
condition friggi;
condition attesaCliente;
condition attesaPiero;
condition pronti;
int nbomb = 0;
bool MarioDeveFriggere = false;
public int friggi_i(){
if(nbomb>0 or MarioDeveFriggere==true){
wait(friggi);
}
return nbomb;
}
public void arrivoCliente(){
wait(attesaCliente);
}
public void friggi_f(){
nbomb = 30;
MarioDeveFriggere = false;
signal(pronti);
}
public void servi_i(){
if(empty(attesaCliente){
wait(attesaPiero);
}
if(nbomb==0 or MarioDeveFriggere){
wait(pronti);
}
signal(attesaCliente);
}
public int servi_f(){
nbomb--;
return nbomb;
}
public void timeout(){
MarioDeveFriggere = true;
}
}
Bancone b;
Clock c;
Process Mario{
int rimasti = 0;
while(true){
rimasti = b.friggi_i();
if(rimasti > 0) < butta >
< friggi >
c.setTimer(60 minuti);
b.friggi_f();
}
}
Process Rosa{
while(true){
c.waitTimer();
b.timeout();
}
}
Process Cliente{
b.arrivoCliente();
< mangia >
}
Process Piero{
int rimasti = 0;
while(true){
b.servi_i();
< servi >
rimasti = b.servi_f();
if(rimasti == 0) c.setTimer(0);
}
}
Monitor Clock{
int now = 0;
int alarm = -1;
public void setTimer(int n){
if(n == 0){
alarm = -1;
signal(sveglia);
}
else alarm = now+n;
}
public void waitTimer(){
if(alarm == -1 or alarm>tick){
wait(sveglia);
}
}
public void tick(){
now++;
if(now >= alarm){
signal(sveglia);
}
}
}
process HwClock{
while(true){
< hw interrupt >
c.tick();
}
}