[concurrency-interest] Should I avoid compareAndSet with value-based classes?

Alex Otenko oleksandr.otenko at gmail.com
Fri Jul 7 08:27:05 EDT 2017

If you are updating a reference, then CAS can also work. If you are talking about imitating update of the reference by mutating inlined object contents, then you do need synchronized for readers.


> On 7 Jul 2017, at 10:32, Andrew Haley <aph at redhat.com> wrote:
> On 07/07/17 10:23, Alex Otenko wrote:
>> No, not only updates, but reads, too.
>> If you assume non-atomic updates, the problem becomes just like with
>> volatile long - has to use synchronized block for all accesses.
> No.  There is one reference to the Instant, reference updates are
> atomic, and Instant itself is immutable, so none of its state becomes
> visible before all of its fields are initialized.  I do not believe
> that it is necessary for readers to be synchronized.
> -- 
> Andrew Haley
> Java Platform Lead Engineer
> Red Hat UK Ltd. <https://www.redhat.com>
> EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671

More information about the Concurrency-interest mailing list