[ 
https://issues.apache.org/jira/browse/KYLIN-2874?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16196017#comment-16196017
 ] 

liyang commented on KYLIN-2874:
-------------------------------

ref http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html

> Ineffective check in CubeDesc#getInitialCuboidScheduler
> -------------------------------------------------------
>
>                 Key: KYLIN-2874
>                 URL: https://issues.apache.org/jira/browse/KYLIN-2874
>             Project: Kylin
>          Issue Type: Bug
>            Reporter: Ted Yu
>
> {code}
>     public CuboidScheduler getInitialCuboidScheduler() {
>         if (cuboidScheduler != null)
>             return cuboidScheduler;
>         synchronized (this) {
>             if (cuboidScheduler == null) {
>                 cuboidScheduler = CuboidScheduler.getInstance(this);
>             }
> {code}
> Suppose thread 1 obtains the lock and modifies cuboidScheduler.
> This modification can be re-ordered with other correlated field assignments 
> within this critical section at runtime. Thus, checking the value of 
> cuboidScheduler is not an effective test that the critical section has 
> completed unless the guarding lock is held while checking.
> When cuboidScheduler is assigned a newly constructed value, the JVM is 
> allowed to reorder the assignment of the new reference to cuboidScheduler 
> before any field assignments that may occur in the constructor.
> If thread 2 comes and read cuboidScheduler, it may use partially initialized 
> object.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to