VarHandles on non-int-sized fields and atomic operations

John Rose john.r.rose at oracle.com
Tue May 24 02:43:36 UTC 2016


On May 23, 2016, at 4:20 PM, Martin Buchholz <martinrb at google.com> wrote:
> 
> As I said in a previous message, you can implement subword CAS using
> fullword CAS in a loop.
> 
> cas8bit(expect, update) {
>  for (;;) {
>    fullword = atomicRead32()
>    if ((fullword &0xff) != expect) return false;
>    if (cas32(fullword, (fullword & ~0xff) | update) return true;
>  }
> }

Yes, that's the "artisanal" version I would reach for.
It doesn't scale well if there is unrelated activity on nearby bytes.
But, for that matter, "nearby" can mean "within 64 bytes",
which is why we have @Contended for when we really need it.
— John


More information about the core-libs-dev mailing list