Вот реализация метода AtomicInteger.incrementAndGet()
из версии JDK, которую я имею на моей машине:
/**
* Atomically increments by one the current value.
*
* @return the updated value
*/
public final int incrementAndGet() {
for (;;) {
int current = get();
int next = current + 1;
if (compareAndSet(current, next))
return next;
}
}
Как видите, реализация очень похожа на вашу.
PS: Почему вы вычисляете v+1
дважды?