diff --git a/anno2/Galla/MCAD/esercizi2019/bomboloni_sol/bomb-monitor-cliente-marco.txt b/anno2/Galla/MCAD/esercizi2019/bomboloni_sol/bomb-monitor-cliente-marco.txt new file mode 100644 index 0000000..ed4fc3d --- /dev/null +++ b/anno2/Galla/MCAD/esercizi2019/bomboloni_sol/bomb-monitor-cliente-marco.txt @@ -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) + ; + ; + a.settimer(60); + v.riempi(); + } +} + +Process Piero{ + int b; + while(true){ + ; + b = v.servi(); + ; + if (b == 0) + a.settimer(0); + } +} + +Process Rosa{ + while(true){ + a.waittimer(); + v.butta(); + } +} + +Process Clock{ + while(true){ + ; + a.tick(); + } +} + +Process Cliente{ + v.ordina(); +} diff --git a/anno2/Galla/MCAD/esercizi2019/bomboloni_sol/cliente/bomboloni-mess-cliente.java b/anno2/Galla/MCAD/esercizi2019/bomboloni_sol/cliente/bomboloni-mess-cliente.java index 8cea1a1..e312aa3 100644 --- a/anno2/Galla/MCAD/esercizi2019/bomboloni_sol/cliente/bomboloni-mess-cliente.java +++ b/anno2/Galla/MCAD/esercizi2019/bomboloni_sol/cliente/bomboloni-mess-cliente.java @@ -50,7 +50,6 @@ process Mario{ setTimer(60); send(s) to p.rilascio_vassoio; - } } diff --git a/anno2/Galla/MCAD/esercizi2019/bomboloni_sol/mia_rendevouz b/anno2/Galla/MCAD/esercizi2019/bomboloni_sol/mia_rendevouz index ceb7b5d..c1880b2 100644 --- a/anno2/Galla/MCAD/esercizi2019/bomboloni_sol/mia_rendevouz +++ b/anno2/Galla/MCAD/esercizi2019/bomboloni_sol/mia_rendevouz @@ -30,7 +30,7 @@ Process Bancone { [] tick >= alarm and alarm != -1; accept wait_timer() -> butta = true; - nbomb = 0; + nbomb = 0; // errore alarm = -1; [] ; accept set_timer(in long n) -> diff --git a/anno2/Galla/MCAD/esercizi2019/bomboloni_monitor.marco b/anno2/Galla/MCAD/esercizi2019/bomboloni_sol/monitor_marco similarity index 91% rename from anno2/Galla/MCAD/esercizi2019/bomboloni_monitor.marco rename to anno2/Galla/MCAD/esercizi2019/bomboloni_sol/monitor_marco index 0ade2a8..c0e2914 100644 --- a/anno2/Galla/MCAD/esercizi2019/bomboloni_monitor.marco +++ b/anno2/Galla/MCAD/esercizi2019/bomboloni_sol/monitor_marco @@ -1,93 +1,80 @@ -monitor Vassoio{ - int b = 0; - timer_scaduto = false; - condition servi; - condition friggi; - - public int servi(){ - if (b == 0 || timer_scaduto){ - wait(servi); - } - servi --; - 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); - } -} - -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){ - alarm = now + s; - } -} - -Vassoio v; -Alarm a; - -Process Mario{ - int b; - while(true){ - b = v.friggi(); - if(b > 0) - ; - ; - a.settimer(60); - v.riempi(); - } -} - -Process Piero{ - int b; - while(true){ - ; - b = v.servi(); - ; - if (b == 0) - a.settimer(0); - } -} - -Process Rosa{ - while(true){ - a.waittimer(); - v.butta(); - } -} - -Process Clock{ - while(true){ - ; - a.tick(); - } -} \ No newline at end of file +monitor Vassoio{ + int b = 0; + timer_scaduto = false; + condition servi; + condition friggi; + public int servi(){ + if (b == 0 || timer_scaduto){ + wait(servi); + } + servi --; + 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); + } +} +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){ + alarm = now + s; + } +} +Vassoio v; +Alarm a; +Process Mario{ + int b; + while(true){ + b = v.friggi(); + if(b > 0) + ; + ; + a.settimer(60); + v.riempi(); + } +} +Process Piero{ + int b; + while(true){ + ; + b = v.servi(); + ; + if (b == 0) + a.settimer(0); + } +} +Process Rosa{ + while(true){ + a.waittimer(); + v.butta(); + } +} +Process Clock{ + while(true){ + ; + a.tick(); + } +} diff --git a/anno2/Galla/MCAD/esercizi2019/bomboloni_sol/secondo_appello/bomb-mess b/anno2/Galla/MCAD/esercizi2019/bomboloni_sol/secondo_appello/bomb-mess new file mode 100644 index 0000000..4fcb32f --- /dev/null +++ b/anno2/Galla/MCAD/esercizi2019/bomboloni_sol/secondo_appello/bomb-mess @@ -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; + } +} \ No newline at end of file diff --git a/anno2/Galla/MCAD/esercizi2019/bomboloni_sol/secondo_appello/bomb-mon b/anno2/Galla/MCAD/esercizi2019/bomboloni_sol/secondo_appello/bomb-mon new file mode 100644 index 0000000..b40fbfa --- /dev/null +++ b/anno2/Galla/MCAD/esercizi2019/bomboloni_sol/secondo_appello/bomb-mon @@ -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(); + } +} \ No newline at end of file