• 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: Programming Context Menu
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Programming Context Menu


  • Subject: Re: Programming Context Menu
  • From: Chris Hanson <email@hidden>
  • Date: Mon, 04 Apr 2011 22:10:00 -0700

On Apr 4, 2011, at 12:38 PM, Bing Li <email@hidden> wrote:

>        if (nil == defaultMenu)
>        {
>                @synchronized(self)
>                {
>                        if (nil == defaultMenu)

Don't do this. I don't mean just in Cocoa either, I mean don't do it ever. It's an anti-pattern called "double-checked locking" and it's fatally broken under most languages' memory models.

If you want to initialize a value once-and-only-once, use dispatch_once or (if you need to support an OS version without GCD) use pthread_once.

  -- Chris

_______________________________________________

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: Programming Context Menu
      • From: "Stephen J. Butler" <email@hidden>
References: 
 >Programming Context Menu (From: Bing Li <email@hidden>)

  • Prev by Date: Re: Adding a 'usro' resource
  • Next by Date: Re: Programming Context Menu
  • Previous by thread: Re: Programming Context Menu
  • Next by thread: Re: Programming Context Menu
  • Index(es):
    • Date
    • Thread