Created
July 12, 2014 12:41
-
-
Save adohe-zz/e73e0530312a3e0e0023 to your computer and use it in GitHub Desktop.
Memory visibility when lack of synchronization
This file contains hidden or 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
| package com.ado.java; | |
| public class NoVisibility { | |
| private static int number; | |
| private static boolean ready; | |
| private static class ReaderThread extends Thread { | |
| @Override | |
| public void run() { | |
| while (!ready) | |
| Thread.yield(); | |
| System.out.println(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