From dab182c81e5d08aa2cda361c676467b8cf57a47e Mon Sep 17 00:00:00 2001 From: Francesco Mecca Date: Mon, 3 Dec 2018 23:28:13 +0100 Subject: [PATCH] scritte, per favore Piede --- .../bomboloni_sol/mia_messagepassing | 74 ++++++++++++++- .../esercizi2019/bomboloni_sol/mia_monitor | 90 +++++++++++++++++++ .../esercizi2019/bomboloni_sol/mia_rendevouz | 11 ++- .../esercizi2019/bomboloni_sol/mia_semafori | 53 +++++++++++ 4 files changed, 222 insertions(+), 6 deletions(-) create mode 100644 anno2/YearI/FirstSem/MCAD/slides/esercizi2019/bomboloni_sol/mia_monitor create mode 100644 anno2/YearI/FirstSem/MCAD/slides/esercizi2019/bomboloni_sol/mia_semafori diff --git a/anno2/YearI/FirstSem/MCAD/slides/esercizi2019/bomboloni_sol/mia_messagepassing b/anno2/YearI/FirstSem/MCAD/slides/esercizi2019/bomboloni_sol/mia_messagepassing index 106a6b8..00dfffa 100644 --- a/anno2/YearI/FirstSem/MCAD/slides/esercizi2019/bomboloni_sol/mia_messagepassing +++ b/anno2/YearI/FirstSem/MCAD/slides/esercizi2019/bomboloni_sol/mia_messagepassing @@ -14,6 +14,76 @@ Process Bancone { do [] nbomb == 0 or butta; p = receive(s) from friggi_i -> - send(s) to p.ok; + send(nbomb) to p.ok; - [] ; receive(s) from friggi_f + [] ; receive(s) from friggi_f; + nbomb = 30; + butta = false; + alarm = tick + 60; + + [] nbomb > 0 and !butta; p = receive(s) from servi_i -> + send(s) to p.ok; + + [] ; receive(s) from servi_f -> + nbomb--; + + [] tick >= alarm; p = receive(s) from wait_timer -> + send(s) to p.ok; + + [] butta == false; receive(s) from scaduti -> + butta = true; + + [] ; receive(s) from clock -> + tick++; + + [] ; receive(n) from set_timer -> + alarm += n; + + od +} + +Process Mario { + int b_rimasti = 0; + signal s; + port signal ok; + + while(true){ + send(s) to Bancone.friggi_i; + receive(b_rimasti) from ok; + if(b_rimasti) < butta >; + < friggi bomboloni > + send(s) to Bancone.friggi_f; + } +} + +Process Piero { + signal s; + port signal ok; + + while(true){ + send(s) to Bancone.servi_i; + receive(s) from ok; + < servi cliente > + send(s) to Bancone.servi_f; + } +} + +Process Rosa { + signal s; + port signal ok; + + while(true){ + send(s) to Bancone.wait_timer; + receive(s) from ok; + send(s) to Bancone.scaduti; + send(s) to Bancone.settimer(60); + } +} + +Process Clock { + signal s; + while(true){ + < hw clock > + send(s) to Bancone.clock; + } +} diff --git a/anno2/YearI/FirstSem/MCAD/slides/esercizi2019/bomboloni_sol/mia_monitor b/anno2/YearI/FirstSem/MCAD/slides/esercizi2019/bomboloni_sol/mia_monitor new file mode 100644 index 0000000..c3dbf68 --- /dev/null +++ b/anno2/YearI/FirstSem/MCAD/slides/esercizi2019/bomboloni_sol/mia_monitor @@ -0,0 +1,90 @@ +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(); + } +} \ No newline at end of file diff --git a/anno2/YearI/FirstSem/MCAD/slides/esercizi2019/bomboloni_sol/mia_rendevouz b/anno2/YearI/FirstSem/MCAD/slides/esercizi2019/bomboloni_sol/mia_rendevouz index e98310f..e607d11 100644 --- a/anno2/YearI/FirstSem/MCAD/slides/esercizi2019/bomboloni_sol/mia_rendevouz +++ b/anno2/YearI/FirstSem/MCAD/slides/esercizi2019/bomboloni_sol/mia_rendevouz @@ -2,7 +2,7 @@ Process Bancone { int nbomb = 0; long tick = 0, alarm = -1; bool butta = false; - entry friggi_i; + entry friggi_i(out int rimasti); entry friggi_f; entry servi_cliente_i; entry servi_cliente_f; @@ -12,7 +12,8 @@ Process Bancone { entry set_timer (in long n); do - [] nbomb == 0 or butta; accept friggi_i(); + [] nbomb == 0 or butta; accept friggi_i(out nrimasti); + nrimasti = nbomb; [] ; accept friggi_f() -> nbomb = 30; @@ -41,8 +42,10 @@ Process Bancone { } Process Mario { + int nrimasti; while(true){ - call Bancone.friggi_i(); + call Bancone.friggi_i(nrimasti); + if(nrimasti) < butta >; < friggi bomboloni > call Bancone.friggi_f(); } @@ -50,6 +53,7 @@ Process Mario { Process Piero { while(true){ + < attendi cliente > call Bancone.servi_cliente_i(); < servi cliente > call Bancone.servi_cliente_f(); @@ -60,7 +64,6 @@ Process Rosa { while(true){ call Bancone.wait_timer(); call Bancone.butta(); - < butta > call Bancone.set_timer(60); } } diff --git a/anno2/YearI/FirstSem/MCAD/slides/esercizi2019/bomboloni_sol/mia_semafori b/anno2/YearI/FirstSem/MCAD/slides/esercizi2019/bomboloni_sol/mia_semafori new file mode 100644 index 0000000..d8c2f23 --- /dev/null +++ b/anno2/YearI/FirstSem/MCAD/slides/esercizi2019/bomboloni_sol/mia_semafori @@ -0,0 +1,53 @@ +Semaphore mut = 1; +Semaphore pierasem = 0; +Semaphore mariosem = 1; +Semaphore pierosem = 0 +int nbomb = 0; +boolean attesaPiero; + +Process Mario{ + while(true){ + P(mariosem); + < friggi > + P(mut); + nbomb = 30; + if(attesaPiero) + attesaPiera = false; + V(pierosem); + if(butta == true) // e` stata Rosa + butta = false; + V(rosasem) + V(mut); + } +} + +Process Piero{ + while(true){ + < attesa cliente > + P(pierosem); + P(mut); + nbomb --; + V(mut) + + < servi cliente > + + P(mut) + if(nbomb == 0) + V(mariosem); + attesaPiero = true; + else + V(pierosem); + V(mut) + } +} + +Process Rosa{ + while(true){ + wait_timer(); + P(mut); + butta = true; + V(mut); + P(rosasem); + set_timer(60); + } +} \ No newline at end of file