Created
December 31, 2013 02:22
-
-
Save dschobel/8191509 to your computer and use it in GitHub Desktop.
concurrent java code which should expose a visibility bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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