title: Why can "Java Concurrency in Practice Listing 10.5." produce a complete snapshot?
body: <p>I am reading <em>Java Concurrency in Practice</em> and encounter the following code snippet.</p>
  
  <pre><code>// Listing 10.5. Lock-ordering deadlock between cooperating objects. Don’t do this.
  
  import java.util.HashSet;
  import java.util.Set;
  
  // Warning: deadlock-prone!
  class Taxi {
      @GuardedBy("this")
      private Point location, destination;
      private final Dispatcher dispatcher;
  
      public Taxi(Dispatcher dispatcher) {
          this.dispatcher = dispatcher;
      }
  
      public synchronized Point getLocation() {
          return location;
      }
  
      public synchronized void setLocation(Point location) {
          this.location = location;
          if (location.equals(destination))
              dispatcher.notifyAvailable(this);
      }
  }
  
  class Dispatcher {
      @GuardedBy("this")
      private final Set&lt;Taxi&gt; taxis;
      @GuardedBy("this")
      private final Set&lt;Taxi&gt; availableTaxis;
  
      public Dispatcher() {
          taxis = new HashSet&lt;Taxi&gt;();
          availableTaxis = new HashSet&lt;Taxi&gt;();
      }
  
      public synchronized void notifyAvailable(Taxi taxi) {
          availableTaxis.add(taxi);
      }
  
      public synchronized Image getImage() {
          Image image = new Image();
          for (Taxi t : taxis)
              image.drawMarker(t.getLocation());
          return image;
      }
  }
  </code></pre>
  
  <p>It then says:</p>
  
  <blockquote>
    <p>In the deadlock-prone version, getImage produces a complete snapshot of the fleet locations at that instant.</p>
  </blockquote>
  
  <p>When calling <code>getImage</code>, we get Dispatcher's intrinsic lock, other threads can't modify <code>taxis</code>, <strong>but</strong> other threads can still modify the <code>location</code> of <code>Taxi</code> although the thread calling <code>getImage</code> <strong>might not</strong> see the change. So, <strong>why can <code>getImage</code> produces a complete snapshot of the fleet locations at that instant?</strong></p>