[ https://issues.apache.org/jira/browse/KYLIN-1563?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15239043#comment-15239043 ]
wangxianbin commented on KYLIN-1563: ------------------------------------ hey guys! check this out, https://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html. it says that "Volatile fields are special fields which are used for communicating state between threads. Each read of a volatile will see the last write to that volatile by any thread; in effect, they are designated by the programmer as fields for which it is never acceptable to see a "stale" value as a result of caching or reordering. The compiler and runtime are prohibited from allocating them in registers. They must also ensure that after they are written, they are flushed out of the cache to main memory, so they can immediately become visible to other threads. Similarly, before a volatile field is read, the cache must be invalidated so that the value in main memory, not the local processor cache, is the one seen. There are also additional restrictions on reordering accesses to volatile variables.". so volatile on initiated may can solve our problem. > 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)