<<< Object class methods for inter-thread communication | Index | Thread setPriority method >>> |
boolean taken = false; public synchronized void grab() throws InterruptedException { while ( taken ) { wait(); // wait unti my turn } taken = true; // okay, my turn! } public synchronized void drop() { taken = false; notifyAll() // wake up all waiting threads } // Client code: resource.grab(); // Critical section: do something with the resource resource.drop();
<<< Object class methods for inter-thread communication | Index | Thread setPriority method >>> |