<AWT Dev> numAppContexts in AppContext modified in not-thread-safe way.
linuxhippy at gmail.com
Fri Aug 19 15:12:55 PDT 2011
The original code is rather strange. The static field will be default
> initialized to zero, the AppContext constructor will increment it to 1, then
> the static block explicitly sets it to one.
> It would be cleaner/clearer if the field were declared and initialized
> before the static block.
Agreed. Please find the modified patch at:
That's an uninteresting case from a data-race perspective though because the
> counter is only ever written once.
In the constructor the non-atomic increment can cause a missed update and
therefor cause numAppContexts to become 1 or even 0, which could trigger
that logic unintentionally.
However I now wonder about how often this gets called in a Swing app? If
> this is a frequent call then the overhead of the atomic might be
> significant. Perhaps the Swing folk should be evaluating this change as
Did some benchmarks, and at least on x86 AtomicInteger.get() performs
identical to a volatile field read.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the awt-dev