关于volatile,找了一堆资料看,看完后想找一个方法去做测试,测了很久,感觉跟没有一样. 这本书<深入理解Java内存模型>,对volatile描述中有这样一个比喻的说法,如下代码所示,对a的读写相当于对b的同步读写. public volatile int a = 0; private int b = 0; public synchronized int getB(){ return b; } public synchronized void setB(int b){ this.b =…
SpinLock实现,摘自并发编程网 package com.juc.simple; import java.util.concurrent.atomic.AtomicReference; /** * a implement of spinlock based on cas * */ public class SpinLock { private AtomicReference<Thread> sign = new AtomicReference<>(); /** * 让当前线程不…