Mixing Atomic*FieldUpdater with 'regular' volatile access

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Mixing Atomic*FieldUpdater with 'regular' volatile access

JSR166 Concurrency mailing list
I'm hunting for a document which describes the consequence of mixing
accesses through Atomic*FieldUpdater with regular accesses to the
volatile field. Particularly:

* If I manage a field using an AFU, do I have to use AFU.get() to read
the field?
* What about set() vs regular write?
* Does using AFU matter for any non-CAS operation? Why?

Thank you.

S.
_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Mixing Atomic*FieldUpdater with 'regular' volatile access

JSR166 Concurrency mailing list
The JavaDoc for java.util./concurrent.atomic (e.g. https://docs.oracle.com/javase/8/docs/api/index.html?java/util/concurrent/atomic/package-summary.html) is pretty clear on this, I think.

> On Mar 30, 2019, at 1:32 PM, Shevek via Concurrency-interest <[hidden email]> wrote:
>
> I'm hunting for a document which describes the consequence of mixing accesses through Atomic*FieldUpdater with regular accesses to the volatile field. Particularly:
>
> * If I manage a field using an AFU, do I have to use AFU.get() to read the field?

According to the JavaDoc:
"get has the memory effects of reading a volatile variable."

> * What about set() vs regular write?

According to the JavaDoc:
"set has the memory effects of writing (assigning) a volatile variable."

> * Does using AFU matter for any non-CAS operation? Why?

Nope. You can do either. The reason AFU has get/set operations
is probably that code using it might only have the AFU instance
visible, and not the volatile field.

>
> Thank you.
>
> S.
> _______________________________________________
> Concurrency-interest mailing list
> [hidden email]
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest


_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Mixing Atomic*FieldUpdater with 'regular' volatile access

JSR166 Concurrency mailing list
On 3/30/19 2:00 PM, Gil Tene wrote:
> The JavaDoc for java.util./concurrent.atomic (e.g. https://docs.oracle.com/javase/8/docs/api/index.html?java/util/concurrent/atomic/package-summary.html) is pretty clear on this, I think.

Thank you. I bashed through the class javadoc and the source, but didn't
think to look at the package javadoc.

This makes perfect sense now.

S.

>> On Mar 30, 2019, at 1:32 PM, Shevek via Concurrency-interest <[hidden email]> wrote:
>>
>> I'm hunting for a document which describes the consequence of mixing accesses through Atomic*FieldUpdater with regular accesses to the volatile field. Particularly:
>>
>> * If I manage a field using an AFU, do I have to use AFU.get() to read the field?
>
> According to the JavaDoc:
> "get has the memory effects of reading a volatile variable."
>
>> * What about set() vs regular write?
>
> According to the JavaDoc:
> "set has the memory effects of writing (assigning) a volatile variable."
>
>> * Does using AFU matter for any non-CAS operation? Why?
>
> Nope. You can do either. The reason AFU has get/set operations
> is probably that code using it might only have the AFU instance
> visible, and not the volatile field.
>
>>
>> Thank you.
>>
>> S.
>> _______________________________________________
>> Concurrency-interest mailing list
>> [hidden email]
>> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>
_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: Mixing Atomic*FieldUpdater with 'regular' volatile access

JSR166 Concurrency mailing list
While the doc does indeed say you need to go through the API, Doug Lea has previously indicated on this list that this really doesn’t apply any longer.  See http://cs.oswego.edu/pipermail/concurrency-interest/2017-September/016176.html

Of course if you’re on Java 9, you can just use VarHandles which I believe explicitly doc this style as being safe.

Mark

On Mar 30, 2019, at 5:06 PM, Shevek via Concurrency-interest <[hidden email]> wrote:

On 3/30/19 2:00 PM, Gil Tene wrote:
The JavaDoc for java.util./concurrent.atomic (e.g. https://docs.oracle.com/javase/8/docs/api/index.html?java/util/concurrent/atomic/package-summary.html) is pretty clear on this, I think.

Thank you. I bashed through the class javadoc and the source, but didn't think to look at the package javadoc.

This makes perfect sense now.

S.

On Mar 30, 2019, at 1:32 PM, Shevek via Concurrency-interest <[hidden email]> wrote:

I'm hunting for a document which describes the consequence of mixing accesses through Atomic*FieldUpdater with regular accesses to the volatile field. Particularly:

* If I manage a field using an AFU, do I have to use AFU.get() to read the field?
According to the JavaDoc:
"get has the memory effects of reading a volatile variable."
* What about set() vs regular write?
According to the JavaDoc:
"set has the memory effects of writing (assigning) a volatile variable."
* Does using AFU matter for any non-CAS operation? Why?
Nope. You can do either. The reason AFU has get/set operations
is probably that code using it might only have the AFU instance
visible, and not the volatile field.

Thank you.

S.
_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest