[concurrency-interest] a question regarding thedouble-checke dlocking

Gregg Wonderly gergg at cox.net
Mon Jun 19 11:56:35 EDT 2006


Rémi Forax wrote:
> Bill Pugh a écrit :
>>On Jun 19, 2006, at 5:29 AM, Yechiel Feffer wrote:
>>>I am concerned with general correctness of my code,
>>>want to avoid the price of volatile, here is a quote from jsr133 FAQ
>>>"However, for fans of double-checked locking (and we really hope  
>>>there are none left), the news is still not good. The whole point  
>>>of double-checked locking was to avoid the performance overhead of  
>>>synchronization. Not only has brief synchronization gotten a LOT  
>>>less expensive since the Java 1.0 days, but under the new memory  
>>>model, the performance cost of using volatile goes up, almost to  
>>>the level of the cost of synchronization. So there's still no good  
>>>reason to use double-checked-locking"
>>
>>That is not from the JSR 133 FAQ.
>>  
> 
> using google the quote seems issued from this thread :
> http://www.theserverside.com/patterns/thread.tss?thread_id=39606#206141
> not from the FAQ.
> 
>>The person who wrote that doesn't know what they are talking about.
>>
>>The cost of a volatile read is significantly less than synchronization.
>>In fact, you would be hard pressed to find an increase over the cost of
>>a normal read in a double checked locking usage.

http://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html

Does in fact contain the text:

     However, for fans of double-checked locking (and we really hope
     there are none left), the news is still not good. The whole
     point of double-checked locking was to avoid the performance
     overhead of synchronization. Not only has brief synchronization
     gotten a LOT less expensive since the Java 1.0 days, but under
     the new memory model, the performance cost of using volatile
     goes up, almost to the level of the cost of synchronization.
     So there's still no good reason to use double-checked-locking.

     Instead, use the Initialization On Demand Holder idiom, which
     is thread-safe and a lot easier to understand:

So, it would appear that there is some kind of disparity in thoughts and words here.

Gregg Wonderly


More information about the Concurrency-interest mailing list