[concurrency-interest] AtomicInteger.getAndIncrement()

Hans Boehm Hans.Boehm at hp.com
Sat Dec 12 21:46:14 EST 2009

On Sat, 12 Dec 2009, bank kus wrote:

> Is this guaranteed to complete in a finite number of steps. Asking
> because am evaluating if I can implement ticket locking using this.
> On a 16 virtual core system if all 16 vcores simultaneously had
> threads invoke this operation ..
> <a> are all vcores guaranteed to block context switching to any other
> threads on their runqueues until this operation completes
> <b> is there fair arbitration between cores. The pathological case
> being vcore 2 gets to increment  then gets to do it again while other
> vcores wait trying to do so.
> I understand this would depend upon the hw instructions used but am
> curious if any fair expectation can be made out of this API.
Given that that the JLS is intentionally silent on any sort of fairness 
guarantee for thread scheduling, I doubt that you can guarantee anything 
of this kind without making some platform assumptions.  I expect that 
general purpose implementations and most hardware will generally do the 
right thing ...


More information about the Concurrency-interest mailing list