[jmm-dev] bitwise RMW operators, specifically testAndSetBit/BTS

Martin Buchholz martinrb at google.com
Fri Jul 22 20:50:57 UTC 2016


On Fri, Jul 22, 2016 at 4:11 AM, Doug Lea <dl at cs.oswego.edu> wrote:

>
> The recommended usage is that (as has always been the case), concurrently
> accessible fields should be declared as volatile. This provides safe
> defaults.
> People can then use VH for other (non-Plain) access methods.
> If people follow this usage guidance, all is well. Except that this doesn't
> hold for array elements, that cannot be declared as volatile.
> Here, usages relying on access atomicity must use only non-Plain access
> methods.  This is not always easy to ensure -- people need to avoid
> calling other methods that might access elements without VarHandles
> unless there is no possibility of concurrent access during call.
> But people writing intentionally racy code using arrays need to be careful
> about things like this anyway.


Is it reasonable to add syntax for volatile array elements?
There's obvious confusion between the reference and the elements, e.g. we
already have
volatile int[] volatile_array_reference;
It could go like C declarations.  Then we would get
(volatile int)[] array_with_volatile_elements;
volatile (volatile int)[] volatile_array_reference_with_volatile_elements;

Yeah, they'll hate us forever for adding that!


More information about the jmm-dev mailing list