[concurrency-interest] Should I avoid compareAndSet with value-based classes?
michael.hixson at gmail.com
Wed Jul 5 23:59:52 EDT 2017
AtomicReference and VarHandle are specified to use == in compareAndSet
(and related) operations . Using == to compare instances of
value-based classes may lead to "unpredictable results" . Does
this mean I should avoid using compareAndSet with arguments that are
instances of value-based classes?
It seems like the documentation clearly tells me "yes, avoid doing
that" but I'm hoping I misunderstood, or maybe AtomicReference and
VarHandle are exempt somehow. Otherwise, how do I implement
non-broken compareAndSet and updateAndGet for a java.time.Instant
value for example? Do I have to box the value in something that's not
a value-based class first, like AtomicReference<Box<Instant>>?
More information about the Concurrency-interest