package GoIntoConcurrency;

/**
 *
 * 一.原子性：指一个操作是不可中断的。即使在多线程一起执行的时候，一个操作一旦开始就不会被干扰。
 * int型是原子操作类型。但在32位系统来说，long型数据的读写不是原子类型的。因为long型长度是64位。
 * 64位和32位是系统的寻址长度。
 *
 * Created by chenyang on 2017/2/19.
 */
public class MultiThreadLong {
    public static long t=0;
    public static class ChangeT implements Runnable{
        private long to;

        public ChangeT(long to) {
            this.to = to;
        }

        public void run() {
            while (true){
                MultiThreadLong.t=to;
                Thread.yield();
            }
        }
    }

    public static class ReadT implements Runnable{
        public void run() {
            while (true){
                long tmp=MultiThreadLong.t;
                if(tmp!=111L&&tmp!=-999L&&tmp!=333L&&tmp!=-444L){
                    System.out.println(tmp);
                }
            }
        }
    }

    public static void main(String[] args) {
        new Thread(new ChangeT(111L)).start();
        new Thread(new ChangeT(-999L)).start();
        new Thread(new ChangeT(333L)).start();
        new Thread(new ChangeT(-444)).start();
        new Thread(new ReadT()).start();
    }
}

@@ -156,19 +156,100 @@
 %E7%B3%BB%E7%BB%9F%E7%9A%84%E5%AF%BB%E5%9D%80%E9%95%BF%E5%BA%A6%E3%80%82
-%0A *
+%E4%B8%A4%E6%AC%A1%E5%8A%A8%E4%BD%9C%E6%89%8D%E8%83%BD%E5%AE%8C%E6%88%9032%E4%BD%8D%E7%B3%BB%E7%BB%9F%E4%B8%8Blong%E5%9E%8B%E7%9A%84%E8%B5%8B%E5%80%BC%E3%80%82%E6%89%80%E4%BB%A5%E4%BC%9A%E5%8F%91%E7%94%9F%E6%B7%B7%E4%B9%B1%E3%80%82%0A * %E4%BA%8C.%E5%8F%AF%E8%A7%81%E6%80%A7%EF%BC%9A%E5%BD%93%E4%B8%80%E4%B8%AA%E7%BA%BF%E7%A8%8B%E4%BF%AE%E6%94%B9%E4%BA%86%E6%9F%90%E4%B8%80%E4%B8%AA%E5%85%B1%E4%BA%AB%E5%8F%98%E9%87%8F%E7%9A%84%E5%80%BC%EF%BC%8C%E5%85%B6%E4%BB%96%E7%BA%BF%E7%A8%8B%E6%98%AF%E5%90%A6%E8%83%BD%E5%A4%9F%E7%AB%8B%E5%8D%B3%E7%9F%A5%E9%81%93%E8%BF%99%E4%B8%AA%E4%BF%AE%E6%94%B9%E3%80%82%E5%90%A6%E5%88%99%E4%BC%9A%E4%BA%A7%E7%94%9F%E8%84%8F%E8%AF%BB%E3%80%82
 %0A * Crea

update code