bug-classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug classpath/22674] Incorrect synchronization in java.util.logging.Err


From: gcc-bugzilla at gcc dot gnu dot org
Subject: [Bug classpath/22674] Incorrect synchronization in java.util.logging.ErrorManager
Date: 16 Oct 2005 01:26:29 -0000

ErrorManager.error is a method that should only be executed once. To achieve
this a field is set so that subsequent invocations return immediately.
Synchronization is needed to ensure that only one thread successfully makes the
single call that sets the field.

To avoid synchronization on every call to error() a form of double-checked
locking is used. However, the double-checked locking idiom does not work unless
combined with the use of volatile variables (and even then that depends on the
usage until the new Java Memory Model is finalised and adopted).

In this case the everUsed field must be marked as volatile so that all threads
are guaranteed to see the value set in it by the thread that successfully
acquires the lock.

A second issue is that the lock used is that of the ErrorManager class object.
This forces threads using different ErrorManager objects to serialize through
the same lock. This is unnecessary. The lock used can simply be that of 'this',
or a private Object used solely for locking purposes.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22674





reply via email to

[Prev in Thread] Current Thread [Next in Thread]