previous | start | next

## Deadlocks

- Not enough to synchronize `add`,`remove`
- `if (!queue.isFull()) queue.add(...);`
  can still be interrupted
- Must move test inside `add` method

      public void add(E newValue)
      {
         queueLock.lock();
         try
         {
            while (queue is full)
               wait for more space
            . . .
         }
         finally { qeueLock.unlock(); }
      }

- Problem: nobody else can call `remove`

previous | start | next