title: How do visibility problems occur in Java concurrency?
body: <p>I am reading the book: "Java Concurrency in Practice" to better understand how java concurrency works. On chapter 3 section 3.1:Visibility There is and example in which the book tries to show how visibility problems occur. Here is the example code (Listing 3.1 in the book):</p>
  
  <pre><code>
  public class NoVisibility {
      private static boolean ready;
      private static int number;
  
      private static class ReaderThread extends Thread {
          public void run() {
              while (!ready)
                  Thread.yield();
              System.out.println(number);
          }
      }
  
      public static void main(String[] args) {
          new ReaderThread().start();
          number = 42;
          ready = true;
      }
  }
  </code></pre>
  
  <p>The book says that the NoVisibility could loop forever because the    value of ready might never become visible to the reader thread. How    is that possible. My general understanding is that ready will become    true at a certain time anyhow. But I can't understand why this might    not happen and the loop goes forever. Can someone help me to    understand this better.</p>