On Dec 9, 2011, at 1:11 AM, Uli Kusterer wrote:

> On 09.12.2011, at 07:55, Ken Thomases wrote:
>> 
>> Double-checked locking is broken.  It is an anti-pattern in many languages, 
>> including the C family under most common implementations.  Don't use it.  
>> Google it if you want to confirm.  One reference: 
>> <http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html>.
> 
> Is this an issue that just exists when you want to write against ANSI C, or 
> is this an actual, practical concern when writing on the Mac, for MacOS or 
> iOS?

It is an actual, practical concern.  The compilers can re-order memory 
accesses.  The CPU can, too.

The second and subsequent threads through the double-checked lock can see the 
singleton pointer as non-nil, but the pointed-to object may not be valid.  Its 
content may not have been written to memory, yet.

Regards,
Ken

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to