Why does this simple threaded program get stuck?
Take a look at this simple Java program: import java.lang.*; class A { static boolean done; public static void main(String args[]) { done = false; new Thread() { public void run() { try { Thread.sleep(1000); // dummy work load } catch (Exception e) { done = true; } done = true; } }.start(); while (!done); System.out.println("bye"); } } On one machine, it prints "bye" and exits right away, while on another machine, it doesn't print anything and sits there forever. Why? This is because your boolean is not volatile , therefore Thread s are allowed to cache copies of it and never update them. I