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>
setTimer(60);
send(s) to p.rilascio_vassoio;
}
}

View file

@ -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) ->

View file

@ -3,7 +3,6 @@ monitor Vassoio{
timer_scaduto = false;
condition servi;
condition friggi;
public int servi(){
if (b == 0 || timer_scaduto){
wait(servi);
@ -11,30 +10,25 @@ monitor Vassoio{
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){
@ -42,19 +36,15 @@ monitor Alarm{
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){
@ -66,7 +56,6 @@ Process Mario{
v.riempi();
}
}
Process Piero{
int b;
while(true){
@ -77,14 +66,12 @@ Process Piero{
a.settimer(0);
}
}
Process Rosa{
while(true){
a.waittimer();
v.butta();
}
}
Process Clock{
while(true){
<aspetta un secondo>;

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();
}
}