• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Singletons with ARC
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Singletons with ARC


  • Subject: Re: Singletons with ARC
  • From: Jean-Daniel Dupas <email@hidden>
  • Date: Fri, 09 Dec 2011 10:36:35 +0100

Le 9 déc. 2011 à 08:47, Ken Thomases a écrit :

> 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.
>

It was a real concern on PPC, but on Intel platform AFAIK.
Memory barriers are noop on x86, as it does not perform out of order execution of memory operations.

http://locklessinc.com/articles/singleton_pattern/

That said,avoiding this pattern in the future may be a good thing.

-- Jean-Daniel




_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Singletons with ARC
      • From: Jean-Daniel Dupas <email@hidden>
References: 
 >Singletons with ARC (From: Ben <email@hidden>)
 >RE: Singletons with ARC (From: Abdul Sowayan <email@hidden>)
 >Re: Singletons with ARC (From: Ken Thomases <email@hidden>)
 >Re: Singletons with ARC (From: Uli Kusterer <email@hidden>)
 >Re: Singletons with ARC (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: Singletons with ARC
  • Next by Date: Re: Exceptions and autorelease pools
  • Previous by thread: Re: Singletons with ARC
  • Next by thread: Re: Singletons with ARC
  • Index(es):
    • Date
    • Thread