Reset dispatch_once_t if the initialization failed?
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