class Task extends Thread { private String name; private int id; private Mutex critical; public Task(String name_, int id_, Mutex critical_) { name = name_; id = id_; critical = critical_; } public void describe() { System.out.println(id + "<" + critical + ">:" + name); } public void run() { while (true) { critical.p(id); System.out.println( name + " is CRITICAL!"); Mutex.criticalSection(((Integer)id).toString()); System.out.println( name + " isn't critical anymore."); critical.v(id); Mutex.nonCriticalSection(); } } }