Does this look like a race?

Andrew Haley aph at redhat.com
Wed Aug 13 09:05:56 UTC 2014


On 08/13/2014 08:55 AM, David Holmes wrote:
> On 13/08/2014 1:01 AM, Andrew Haley wrote:
>> (Please forgive me if this should go to the AWT list or somesuch.  It
>> seems to me like this is not really a graphics-related issue, but one
>> of Java concurrency.)
>>
>> This is in JDK9, sun.font.GlyphList.  There is a non-volatile boolean
>> inUse, and it is not always written in a synchronized block.  It is
>> used to allow exclusive access to a singleton instance.
>>
>> It seems to me that, at a minimum, inUse should be volatile, or e.g.
>> strikelist might be overwritten to null after some other thread has
>> started using this GlyphList.  Do you agree?
> 
> Yes, either inUse needs to be volatile and used in a way that ensures 
> the correct happens-before relationships, or dispose() needs to do all 
> modifications to the shared instance inside a synchronized block  and 
> clear inUse in that block.

Yes, I thought so.  There are probably a dozen ways of doing this
correctly, but this way is certainly wrong.

I created
JDK-8054991 - sun.font.GlyphList uses broken double-checked locking

Thanks everyone,
Andrew.



More information about the core-libs-dev mailing list