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