Skip to content

Instantly share code, notes, and snippets.

@dschobel
Created December 31, 2013 02:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dschobel/8191509 to your computer and use it in GitHub Desktop.
Save dschobel/8191509 to your computer and use it in GitHub Desktop.
concurrent java code which should expose a visibility bug
public class Volatile {
private static boolean ready;
private static int number;
public static class ReaderThread extends Thread {
public void run() {
while(!ready)
{
Thread.yield();
}
System.out.println("number is: " + number);
}
}
public static void main(String[] args) {
new ReaderThread().start();
number = 42;
ready = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment