UniTO/anno2/YearI/FirstSem/MCAD/esercizi2019/bomboloni_sol/mia_messagepassing

90 lines
1.7 KiB
Text
Raw Normal View History

2018-12-03 17:53:23 +01:00
Process Bancone {
int nbomb = 0;
long tick = 0;
long alarm = -1;
boolean butta = false;
signal s;
port signal friggi_i;
port signal friggi_f;
port signal servi_i;
port signal servi_f;
port signal wait_timer;
port long set_timer;
port signal scaduti;
do
[] nbomb == 0 or butta; p = receive(s) from friggi_i ->
2018-12-03 23:28:13 +01:00
send(nbomb) to p.ok;
2018-12-03 17:53:23 +01:00
2018-12-03 23:28:13 +01:00
[] ; 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;
}
}