scritte, per favore Piede

This commit is contained in:
Francesco Mecca 2018-12-03 23:28:13 +01:00
parent 0a7668d13f
commit dab182c81e
4 changed files with 222 additions and 6 deletions

View file

@ -14,6 +14,76 @@ Process Bancone {
do do
[] nbomb == 0 or butta; p = receive(s) from friggi_i -> [] nbomb == 0 or butta; p = receive(s) from friggi_i ->
send(nbomb) to p.ok;
[] ; 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; send(s) to p.ok;
[] ; receive(s) from friggi_f [] ; 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;
}
}

View file

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

View file

@ -2,7 +2,7 @@ Process Bancone {
int nbomb = 0; int nbomb = 0;
long tick = 0, alarm = -1; long tick = 0, alarm = -1;
bool butta = false; bool butta = false;
entry friggi_i; entry friggi_i(out int rimasti);
entry friggi_f; entry friggi_f;
entry servi_cliente_i; entry servi_cliente_i;
entry servi_cliente_f; entry servi_cliente_f;
@ -12,7 +12,8 @@ Process Bancone {
entry set_timer (in long n); entry set_timer (in long n);
do do
[] nbomb == 0 or butta; accept friggi_i(); [] nbomb == 0 or butta; accept friggi_i(out nrimasti);
nrimasti = nbomb;
[] ; accept friggi_f() -> [] ; accept friggi_f() ->
nbomb = 30; nbomb = 30;
@ -41,8 +42,10 @@ Process Bancone {
} }
Process Mario { Process Mario {
int nrimasti;
while(true){ while(true){
call Bancone.friggi_i(); call Bancone.friggi_i(nrimasti);
if(nrimasti) < butta >;
< friggi bomboloni > < friggi bomboloni >
call Bancone.friggi_f(); call Bancone.friggi_f();
} }
@ -50,6 +53,7 @@ Process Mario {
Process Piero { Process Piero {
while(true){ while(true){
< attendi cliente >
call Bancone.servi_cliente_i(); call Bancone.servi_cliente_i();
< servi cliente > < servi cliente >
call Bancone.servi_cliente_f(); call Bancone.servi_cliente_f();
@ -60,7 +64,6 @@ Process Rosa {
while(true){ while(true){
call Bancone.wait_timer(); call Bancone.wait_timer();
call Bancone.butta(); call Bancone.butta();
< butta >
call Bancone.set_timer(60); call Bancone.set_timer(60);
} }
} }

View file

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