Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Double-checked locking

  Asked By: Arland    Date: Jun 10    Category: Java    Views: 587

For those who still use double-checked locking to solve synchronization problems, it doesn't work! or at least it doesn't work without volatile modifier


The Initialization on Demand Holder idiom seems very useful.



2 Answers Found

Answer #1    Answered By: Tarron Thompson     Answered On: Jun 10

Cool thing, but I don't count this as a bug or so in JVM. It's rather a typo of programming, since volatile is vital down there.

The point is I once attended a presentation about JDK source code pitfalls and the guy talking (afaik from CMU) had found so many of these kind of bugs inside JDK code, esp in java.util.logger! Seems unbelievable!

That way jroller.com/amin/entry/two_advice_if_you_are

Answer #2    Answered By: Vid Fischer     Answered On: Jun 10

It is not a bug, the standard double-checked locking  doesn't work due to massive changes to the compilers which is made for better performance and regardless of that, new servers are multiproccessor and they have changed their algorithm accessing the memory in terms of speed and performance.

The problem is visibility, which means, the time takes the changes made to a shared variable becomes visible to another thread is indefinite and making the variable volatile guarantees the visibility of modified data across the threads

Didn't find what you were looking for? Find more on Double-checked locking Or get search suggestion and latest updates.