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

wangxianbin commented on KYLIN-1563:
------------------------------------

hi Ted & shaofeng! to be more specific.
Here is a simple example of how volatile fields can be used:
class VolatileExample {
  int x = 0;
  volatile boolean v = false;
  public void writer() {
    x = 42;
    v = true;
  }

  public void reader() {
    if (v == true) {
      //uses x - guaranteed to see 42.
    }
  }
}


Assume that one thread is calling writer, and another is calling reader. The 
write to v in writer releases the write to x to memory, and the read of v 
acquires that value from memory. Thus, if the reader sees the value  true for 
v, it is also guaranteed to see the write to 42 that happened before it. This 
would not have been true under the old memory model.  If v were not volatile, 
then the compiler could reorder the writes in writer, and reader's read of x 
might see 0.


> Unsafe check of initiated in HybridInstance#init()
> --------------------------------------------------
>
>                 Key: KYLIN-1563
>                 URL: https://issues.apache.org/jira/browse/KYLIN-1563
>             Project: Kylin
>          Issue Type: Bug
>            Reporter: Ted Yu
>            Assignee: Shaofeng SHI
>
> {code}
>     private void init() {
>         if (initiated == true)
>             return;
>         synchronized (this) {
>             if (initiated == true)
>                 return;
>             if (realizationEntries == null || realizationEntries.size() == 0)
>                 throw new IllegalArgumentException();
> {code}
> Suppose there are two threads executing the above code.
> Thread1 uses the value read from field initiated in the condition initiated 
> == true. It sees that the condition is false.
> Thread2 checks variable initiated, reading it after Thread1 assigns to 
> initiated but before some of the correlated field assignments take place. It 
> sees the condition initiated == true as being true. It continues on before 
> the critical section has completed, and can read data changed by that 
> critical section while it is in an inconsistent state.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to