Re: Thread-safe singleton with lazy initialisation
Re: Thread-safe singleton with lazy initialisation
- Subject: Re: Thread-safe singleton with lazy initialisation
- From: Simone Tellini <email@hidden>
- Date: Tue, 18 Aug 2015 18:18:37 +0200
Il giorno 18/ago/2015, alle ore 18:00, Maxthon Chan <email@hidden> ha scritto:
>
> So the first class that is required is the main application class CGIApplication. Being the analogue of UIApplication it is a singleton. Is this the proper way of doing it? I cannot use @synchronized yet because there is nothing to lock on:
if you used GCD, it would be simpler:
+ (instancetype)sharedInstance
{
static dispatch_once_t once;
static id ret;
dispatch_once( &once, ^{
ret = [[self alloc] init];
} );
return ret;
}
--
Simone Tellini
http://tellini.info
_______________________________________________
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