I know that double locking check without mutable variable is unsafe based on this link http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html
class Foo { private Helper helper = null; public Helper getHelper() { if (helper == null) { synchronized(this) { if (helper == null) { helper = new Helper(); } } } return helper; } }
I want to simulate this situation on my home computer. I have a standard jdk1.7 and multi-core processor. But I can not imitate disturbed behavior. I use this test http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckTest.java which should simulate this. I also create part of my test, but to no avail. You donβt know how to simulate a situation where this double check idiom without volatility is violated? Thus, it returns a partially created Helper class.
source share