previous | start | next

## Avoiding Deadlocks

- Waiting thread is blocked
- Condition object manages set of threads that wait for the condition to change
- To unblock, another thread must call `signalAll` on the same condition object
- Call when state changes

      public E remove()
      {
         . . .
         E r = elements[head];
         . . .
         spaceAvailableCondition.signalAll(); // Unblock waiting threads
         return r;
      }

  ``
- All waiting threads removed from wait set, unblocked
- Ch9/queue2/BoundedQueue.java

previous | start | next