Re: Global in NSApplication
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