I know that double check locking without volatile
variable is not safe 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 at my home computer. I have standard jdk1.7 and multicore processor. But I am not able to simulate the broken behaviour. I am using this test http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckTest.java that should simulate this. I also create some of my test, but without success. Do you have any idea how to simulate the situation when this double check idiom without volatile is broken? So it returns partially created Helper class.