• 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
Reset dispatch_once_t if the initialization failed?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Reset dispatch_once_t if the initialization failed?


  • Subject: Reset dispatch_once_t if the initialization failed?
  • From: Daryle Walker <email@hidden>
  • Date: Sun, 14 Sep 2014 00:14:51 -0400

I’ve seen bog-standard code to initialize a shared instance like:

> + (SomeSingleton *) sharedInstance
> {
> 	static SomeSingleton *sharedInstance = nil;
> 	static dispatch_once_t onceToken;
> 	static dispatch_once_t onceToken;
> 	dispatch_once(&onceToken, ^{
> 		sharedInstance = [[SomeSingleton alloc] init];
> 	});
> 	return sharedInstance;
> }

What happens if that initialization fails? Shouldn’t there be a test for NIL and a reset of the “onceToken” somewhere?… (Or is the chance of failure too unlikely?)

—
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com

_______________________________________________

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: Reset dispatch_once_t if the initialization failed?
      • From: Kyle Sluder <email@hidden>
  • Prev by Date: Re: NSUserDefaults not sticking
  • Next by Date: Re: Reset dispatch_once_t if the initialization failed?
  • Previous by thread: Re: Loading image resources
  • Next by thread: Re: Reset dispatch_once_t if the initialization failed?
  • Index(es):
    • Date
    • Thread