How atomicity is achieved in the classes defined in java.util.concurrent.atomic package?
问题 I was going through the source code of java.util.concurrent.atomic.AtomicInteger to find out how atomicity is achieved by the atomic operations provided by the class. For instance AtomicInteger.getAndIncrement() method source is as follows public final int getAndIncrement() { for (;;) { int current = get(); int next = current + 1; if (compareAndSet(current, next)) return current; } } I am not able to understand the purpose of writing the sequence of operations inside a infinite for loop. Does