monitor Vassoio{ int b = 0; timer_scaduto = false; condition servi; condition friggi; public int servi(){ if (b == 0 || timer_scaduto){ wait(servi); } 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){ alarm = -1; 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){ 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(); } }