• 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: Global in NSApplication
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Global in NSApplication


  • Subject: Re: Global in NSApplication
  • From: Kyle Sluder <email@hidden>
  • Date: Wed, 27 Jan 2010 13:58:35 -0800

On Wed, Jan 27, 2010 at 1:51 PM, Scott Ribe <email@hidden> wrote:
> The code you posted has a race condition, and can create multiple instances
> when called from different threads.

This is true. My favorite way of avoiding it:

+ (Foo *)sharedFoo {
  static Foo *instance;
  static dispatch_once_t once;
  dispatch_once(&once, ^{ instance = [[Foo alloc] init]; })
  return instance;
}

--Kyle Sluder
_______________________________________________

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: 
 >Re: Global in NSApplication (From: Graham Cox <email@hidden>)
 >Re: Global in NSApplication (From: Scott Ribe <email@hidden>)

  • Prev by Date: CG Path in CALayer versus NSView
  • Next by Date: Re: Global in NSApplication
  • Previous by thread: Re: Global in NSApplication
  • Next by thread: Re: Global in NSApplication
  • Index(es):
    • Date
    • Thread