Can an algorithm using Java AtomicStampedReference be considered non-blocking?

I am trying to implement a non-blocking binary search tree as described here using Java. This algorithm is based on CAS with one world, but:

Field status and information are stored together in the CAS object. Thus, the inner node uses four words of memory.

I decided to use AtomicStampedReference to store this data. The problem is that he

supports stamped links by creating internal objects representing boxed pairs [reference, integer].

Internal implementation of this structure:

public boolean compareAndSet(V   expectedReference,
                             V   newReference,
                             int expectedStamp,
                             int newStamp) {
    Pair<V> current = pair;
    return
        expectedReference == current.reference &&
        expectedStamp == current.stamp &&
        ((newReference == current.reference &&
          newStamp == current.stamp) ||
         casPair(current, Pair.of(newReference, newStamp)));
}

A pair defined as:

private static class Pair<T> {
    final T reference;
    final int stamp;
    private Pair(T reference, int stamp) {
        this.reference = reference;
        this.stamp = stamp;
    }
    static <T> Pair<T> of(T reference, int stamp) {
        return new Pair<T>(reference, stamp);
    }
}

Is this implementation not blocking yet?

: compareAndSet ?

+4
1

?

[ ] , , Java CAS.

, , , CAS, . Wikipedia :

, , , . , ;

...

, .

CAS [ , , CAS while]:

1: CAS? , CAS. , . , , , .

: CAS ? , "" , , ( ).

CAS, Java, AtomicXXX CAS . , - JVM:

public class Entity {
    static {
        new Thread(){
            @Override
            public void run() {
                synchronized (getClass().getClassLoader()){
                    try {
                        getClass().getClassLoader().wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }.start();
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        AtomicReference v = new AtomicReference(new Object());
        Object var = null;
        Object somenew;
        do {
            var = v.get();
            somenew = new Object();
        } while(!v.compareAndSet(var, somenew));
    }

}

, main(), , - , , . , , , ? , cas-lock Java - , cas, .

CAS

CAS . , , , . , , CAS.

Wikipedia quote:

Compare-and-Swap ( Compare-and-Swap-Double) IBM 370 ( ) 1970 .

2013 , CAS .

JDK:

AtomicInteger.compareAndSet() Javadoc :

, value == .

AtomicXXX, , .

AtomicStampedReference.compareAndSet(). Javadoc :

, == , .

, javadoc , , , , , CAS.

+5

Source: https://habr.com/ru/post/1539650/


All Articles