lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dawid Weiss <dawid.we...@gmail.com>
Subject Re: Immutable OpenBitSet?
Date Thu, 28 Apr 2011 12:59:43 GMT
>      static void writer() {
>        f = new FinalFieldExample();
>      }
>      static void reader() {
>        if (f != null) {
>          int i = f.x; // guaranteed to see 3
>          int j = f.y; // could see 0
>        }
>      }
>    }
>

In this snippet of code there's not even a guarantee that reader() will see
the change to field f... I used to create puzzlers for students around spin
loops that got optimized away by hotspot to never again reference the
(condition) field because the code never mutated it inside the loop. So
something like this:

while (f == null) {}

should get jitted into this:

while (true) {}

D.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message