You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by bu...@apache.org on 2003/04/15 16:15:55 UTC

DO NOT REPLY [Bug 19029] New: - Double-checked locking code needs to be reworked

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=19029>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=19029

Double-checked locking code needs to be reworked

           Summary: Double-checked locking code needs to be reworked
           Product: XalanJ2
           Version: CurrentCVS
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Major
          Priority: Other
         Component: Xalan
        AssignedTo: xalan-dev@xml.apache.org
        ReportedBy: zongaro@ca.ibm.com


I recently learned about a problem with a commonly used Java programming 
idiom.  The following coding style appears in a number of places in Xalan-J 
code:

  if (m_staticMember == null) {
    synchronized {
      if (m_staticMember == null) {
        m_staticMember = new Constructor();
      }
    }
  }

The code is trying to perform lazy initialization of a static member, while 
also trying to avoid performing synchronization on all accesses of that static 
member.  This code might not work as expected in a multi-threaded application, 
particularly as compilers and hardward architectures become increasingly 
sophisticated.  For some references that describe the problem, see [1], [2] and 
[3], and [4] for the precise specification of the Java memory model.

I've found instances of this in the following classes, but there may be others; 
we'll need to examine all the synchronized constructs to track down all of them.

  org.apache.xalan.lib.ExsltStrings
  org.apache.xalan.lib.Extensions
  org.apache.xalan.processor.TransformerFactoryImpl
  org.apache.xml.serializer.CharInfo
  org.apache.xpath.operations.Variable


[1] http://www-106.ibm.com/developerworks/java/library/j-dcl.html
[2] http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-double.html
[3] http://www.javaworld.com/javaworld/jw-05-2001/jw-0525-double_p.html
[4] Chapter 17 of Java Language Specification, Second Edition.  Joy, Steele, 
Gosling, Bracha.