lockfree 算法 多线程下不需要加锁

2019PHP高薪工程师学习路线图....>>>

[Java]代码    

private AtomicInteger temp = new AtomicInteger();

    public void set(int value) {

        for (;;) {
            int currentValue = temp.get();
            if (value != currentValue) {
                if (temp.compareAndSet(currentValue, value)) {
                    break;
                } else {
                    continue;
                }
            }
        }
    }