bug-classpath
[Top][All Lists]
Advanced

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

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


From: gcc-bugzilla at gcc dot gnu dot org
Subject: [Bug classpath/22673] Incorrect synchronization in java.util.logging.ErrorManager
Date: 16 Oct 2005 01:26:28 -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.


------- Comment #1 from from-classpath at savannah dot gnu dot org  2003-03-26 
16:37 -------
Can someone please delete the duplicate reports 2945, 2946 and 2947.

The bug submission system seems to have a glitch with browser refreshes. After
submitting the bug I went "back" to the bug list page. Browser says the page
has expired and will "repost" the form (I should have guessed what was
happening). I go back to the bug list page but my bug has been resubmitted a
second time. I look in another bug report and go "back" and the same thing
happens. Finally I realized what was going on. Backing out to the top-level
seemed to fix this.

Sorry about that. This site seems to have a number of navigation problems - eg.
with regard to logging.


------- Comment #2 from from-classpath at savannah dot gnu dot org  2003-06-11 
17:39 -------
Duplicate of #2944


------- Comment #3 from from-classpath at savannah dot gnu dot org  2003-06-11 
17:40 -------
Duplicate of #2944


------- Comment #4 from from-classpath at savannah dot gnu dot org  2003-06-11 
17:40 -------
Duplicate of #2944


------- Comment #5 from from-classpath at savannah dot gnu dot org  2003-10-21 
05:38 -------
(Cited e-mail; From: Sascha Brawer; To: David Holmes)

Would the following patch solve the problem? I'm assuming that VM implementors
are aware of the revised memory model.

[patch that got checked into cvs on 2003-10-21]


------- Comment #6 from from-classpath at savannah dot gnu dot org  2003-10-21 
05:41 -------
(Cited e-mail; From: David Holmes; To: Sascha Brawer)

Yes it does.

This particular usage of the double-check idiom is about the safest you could
have as the flag is the only bit of data involved. My remarks about the new JMM
were more a commentary on the general use of double-checked-locking, where
typically the flag protects access to some data and you're not guaranteed to
see the data even if you see the flag under the old JMM. In this case there is
no data, so this is correct under both old and new JMM - so you could tone down
the comments a little if you like.


-- 


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





reply via email to

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