[concurrency-interest] The code example in onSpinWait() Javadoc

Andrew Haley aph at redhat.com
Thu Nov 14 10:43:45 EST 2019


On 11/14/19 3:31 PM, Francesco Nigro via Concurrency-interest wrote:
>     E o = this.obj;
>     if (o == null && !done) {
>         return null;
>      }
>      //o will be !null at some point
>      do {
>          if (o != null)
>             return o;
>          java.lang.Thread.onSpinWait();
>      } while(true);
> }
> 
> In case like this is more appropriate, maybe, but much less intuitive
> probably.

Umm, what? o is a local. This loop spins forever.

-- 
Andrew Haley  (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671



More information about the Concurrency-interest mailing list