[concurrency-interest] Atomic double arrays

David Holmes dholmes at dltech.com.au
Mon Oct 31 04:44:41 EST 2005


Jonathon,

> Is there a reason util.concurrent has no AtomicDoubleArray class?

Yes because there are no generally available atomic instructions for
operating on floating-point values. So basically your only option is
synchronization using locks.

> There is this throw-away line at the end of the package docs:
> "You can also hold floats using Float.floatToIntBits and
> Float.intBitstoFloat conversions, and doubles using
> Double.doubleToLongBits and Double.longBitsToDouble conversions."
>
> But that doesn't seem to help if you want to use the atomic add
> methods

Right, these techniques allow you to hold float bits and do atomic get/set
and CAS but not general arithmetic - because again there are no atomic
instructions for doing that.

> Is there another way to do atomic double array ops that doesn't
> involve using synchronize?

Nope - locking is really your only option.

Cheers,
David Holmes



More information about the Concurrency-interest mailing list