• 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: "Stephen J. Butler" <email@hidden>
  • Date: Tue, 05 Apr 2011 00:57:13 -0500

On Tue, Apr 5, 2011 at 12:10 AM, Chris Hanson <email@hidden> wrote:
> 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.

It's also worth pointing out that NSMenu is not thread safe, and
should never be accessed off the main thread. So the locking is
pointless anyway!
_______________________________________________

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

References: 
 >Programming Context Menu (From: Bing Li <email@hidden>)
 >Re: Programming Context Menu (From: Chris Hanson <email@hidden>)

  • Prev by Date: Re: Programming Context Menu
  • 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