Thanks for incorporating this change to jasper.  I had suggested it a
couple of months ago (22/11/2000 in fact: see
http://w6.metronet.com/~wjm/tomcat/2000/Nov/msg00747.html)

In the meantime, however, I have been browsing through the sessions of
the JavaOne conference of 2000 and there's (at least) one session of
particular interest: "Correct and Efficient Synchronization of Threads
in the Java Programming Environment" (The complete list including links
to realAudio recordings is on
http://java.sun.com/javaone/javaone00/replay.html)
Here's a direct link to the abstract:
http://jsp.java.sun.com/javaone/javaone2000/event.jsp?eventId=754

One of the points that is made in that session is that even this
'double-check idiom' is NOT thread-safe!
The exact reasons for this are not so easy to understand but basically
what I understood is that within the synchronized block, writes to main
memory can occur in any order, meaning that the value of _jspx_inited
can be commited to main memory while some of the results of the
initialisation code are still in e.g. processor registers.  When the
thread exits the synchonized block, it is required to commit all its
changes to main memory, but if another processor checks the value of
_jspx_inited *before* acquiring the lock, it may see _jspx_inited being
true while not all other initialisation data has actually been written
to main memory.
For more details, please follow the links above...



One if the questions I raised in my earlier post is why this
initialisation code isn't moved to the init() method of the generated
servlet? This moves the responsability for executing the initialization
exactly once to the container where IMHO it belongs...

Luc Vanlerberghe



[EMAIL PROTECTED] wrote:
> 
> horwat      01/01/24 12:26:39
> 
>   Modified:    jasper/src/share/org/apache/jasper/compiler
>                         JspParseEventListener.java
>   Log:
>   Fix _jspx_init() thread safety
> 
>   BR 157
> 
>   Revision  Changes    Path
>   1.21      +11 -3     
>jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspParseEventListener.java
> 
>   Index: JspParseEventListener.java
>   ===================================================================
>   RCS file: 
>/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspParseEventListener.java,v
>   retrieving revision 1.20
>   retrieving revision 1.21
>   diff -u -r1.20 -r1.21
>   --- JspParseEventListener.java        2000/12/22 18:37:39     1.20
>   +++ JspParseEventListener.java        2001/01/24 20:26:39     1.21
>   @@ -1,7 +1,7 @@
>    /*
>   - * $Header: 
>/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspParseEventListener.java,v
> 1.20 2000/12/22 18:37:39 pierred Exp $
>   - * $Revision: 1.20 $
>   - * $Date: 2000/12/22 18:37:39 $
>   + * $Header: 
>/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspParseEventListener.java,v
> 1.21 2001/01/24 20:26:39 horwat Exp $
>   + * $Revision: 1.21 $
>   + * $Date: 2001/01/24 20:26:39 $
>     *
>     * ====================================================================
>     *
>   @@ -333,8 +333,16 @@
>         writer.println();
>            writer.println("if (_jspx_inited == false) {");
>            writer.pushIndent();
>   +     writer.println("synchronized (this) {");
>   +        writer.pushIndent();
>   +        writer.println("if (_jspx_inited == false) {");
>   +        writer.pushIndent();
>            writer.println("_jspx_init();");
>            writer.println("_jspx_inited = true;");
>   +        writer.popIndent();
>   +        writer.println("}");
>   +        writer.popIndent();
>   +        writer.println("}");
>            writer.popIndent();
>            writer.println("}");
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, email: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to