[concurrency-interest] increment()/decrement() methodson atom icInteger ?

Yechiel Feffer yechielf at gigaspaces.com
Tue May 31 05:55:31 EDT 2005

Yes, thanks David, this was my point,delegation of the increment op to the
processor by the JVM,
but I disagree with you that there is no real diff' between cas and atomic
incrementation. This is true for a single threaded env' but in a "packed"
multi-threaded env' the cas retry loop may iterate several times, rejecting
the op'. This can be avoided by a delegated incrementation, and is not
needed in this case since I dont want to know the result after.

Regrds, Yechiel 

-----Original Message-----
From: David Holmes [mailto:dholmes at dltech.com.au]
Sent: Tuesday, May 31, 2005 00:19
To: Brian Goetz; Yechiel Feffer
Cc: concurrency-interest at altair.cs.oswego.edu
Subject: RE: [concurrency-interest] increment()/decrement() methodson
atomicInteger ?

Brian Goetz wrote:
> This does not save the CAS retry cycle.  Increment looks like this:
> while (true) {
>    int i = get();
>    if (cas(i, i+1))
>      return i+1;
> }
> To implement a non-value-returning increment, you'd still have to do this:
> while (true) {
>    int i = get();
>    if (cas(i, i+1))
>      break;
> }
> So there's no performance advantage to having a non-value-returning
> increment operation.

I think Brian and Doug have missed Yechiel's point. If I understand
correctly Yechiel is presuming that increment() et al use a CAS-loop only
because they want to return the old value. Therefore if you don't need the
return value you could implement those methods without using CAS at all.
This is true in principle. On X86 there are explicit instructions that can
be used to do atomic increments and decrements. However - and Doug is the
expert on this - I recall being told that there is no significant
performance gain in using such instructions over using a CAS loop. So all
the atomic ops were written using the CAS-loop, which not only simplifies
the Java code, it also makes life easier for the JIT/VM as it only has to
intrinsify one atomic instruction.

David Holmes
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20050531/c216b603/attachment.htm

More information about the Concurrency-interest mailing list