resource Philosopher import Servant body Philosopher (cap Servant s, int id) int j process phil { for [j=1 to 10] { write ("Philosopher", id, "wants to eat") s.getforks(id) # eat nap((j mod 5)*100) write ("Philosopher", id, "stops eating") s.relforks(id) # think nap((j mod 5)*100) } } end Philosopher resource Servant op getforks (int id) op relforks (int id) const int n = 5 body Servant () process server { bool eating[n] = ([n] false) write ("Servant starts service") while (true) { nap(500); in getforks(id) st (not eating[(id%n)+1]) and (not eating[((id+3)%n)+1]) -> eating[id] = true ; write("Philosopher", id, "eats") [] relforks(id) -> eating[id] = false; write("Philosopher", id, "thinks") ni } } end Servant resource Main () import Philosopher import Servant int id cap Servant s s = create Servant (); for [id=1 to 5] { create Philosopher(s,id) } end Main