Re: Programming Context Menu
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