I could not understand below code snippet from A fix that doesn't work. (I did read the explanation that follows on same page).
If we have 2 synchronized blocks, how is this DCL version broken? Or is it not applicable post Java5?
// (Still) Broken multithreaded version
// "Double-Checked Locking" idiom
class Foo {
private Helper helper = null;
public Helper getHelper() {
if (helper == null) {
Helper h;
synchronized(this) {
h = helper;
if (h == null)
synchronized (this) {
h = new Helper();
} // release inner synchronization lock
helper = h;
}
}
return helper;
}
// other functions and members...
}