compareAndSet
or just CAS
relates to nonblocking thread-safe algorithms. The increment operation in case of addAndGet
is fetching the old value, transform it to the new value and using CAS tries to set the new value, if current
wasn't modified during increment. If CAS
fails, it would be retried until success. This strategy is efficient in cases when there's no extreme contention.
↧
Answer by hahn for Use of infinite loop in AtomicInteger.addAndGet(int)
↧