Commit 75a5a481 by Sascha Brawer Committed by Michael Koch

Fix for bug #2944, reported by David Holmes <dholmes@dltech.com.au>

2003-10-21  Sascha Brawer  <brawer@dandelis.ch>

	Fix for bug #2944, reported by David Holmes <dholmes@dltech.com.au>
        * java/util/logging/ErrorManager.java (everUsed): Made volatile.
        (error): Synchronize on instance, not class.

From-SVN: r72750
parent 63d83744
2003-10-21 Sascha Brawer <brawer@dandelis.ch>
Fix for bug #2944, reported by David Holmes <dholmes@dltech.com.au>
* java/util/logging/ErrorManager.java (everUsed): Made volatile.
(error): Synchronize on instance, not class.
2003-10-21 Mark Wielaard <mark@klomp.org> 2003-10-21 Mark Wielaard <mark@klomp.org>
Reported by M.Negovanovic Reported by M.Negovanovic
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
-- a class for dealing with errors that a Handler encounters -- a class for dealing with errors that a Handler encounters
during logging during logging
Copyright (C) 2002 Free Software Foundation, Inc. Copyright (C) 2002, 2003 Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -100,7 +100,16 @@ public class ErrorManager ...@@ -100,7 +100,16 @@ public class ErrorManager
public static final int FORMAT_FAILURE = 5; public static final int FORMAT_FAILURE = 5;
private boolean everUsed = false; /**
* Indicates whether the {@link #error} method of this ErrorManager
* has ever been used.
*
* Declared volatile in order to correctly support the
* double-checked locking idiom (once the revised Java Memory Model
* gets adopted); see Classpath bug #2944.
*/
private volatile boolean everUsed = false;
public ErrorManager() public ErrorManager()
{ {
...@@ -125,13 +134,19 @@ public class ErrorManager ...@@ -125,13 +134,19 @@ public class ErrorManager
if (everUsed) if (everUsed)
return; return;
synchronized (ErrorManager.class) synchronized (this)
{ {
/* The double check is intentional. If the first check was /* The double check is intentional. If the first check was
* omitted, the monitor would have to be entered every time * omitted, the monitor would have to be entered every time
* error() method was called. If the second check was * error() method was called. If the second check was
* omitted, the code below could be executed by multiple * omitted, the code below could be executed by multiple
* threads simultaneously. * threads simultaneously.
*
* This is the 'double-checked locking' idiom, which is broken
* with the current version of the Java memory model. However,
* we assume that JVMs will have adopted a revised version of
* the Java Memory Model by the time GNU Classpath gains
* widespread acceptance. See Classpath bug #2944.
*/ */
if (everUsed) if (everUsed)
return; return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment