Re: Proper way to create a singleton without @synchronized ?
Re: Proper way to create a singleton without @synchronized ?
- Subject: Re: Proper way to create a singleton without @synchronized ?
- From: WT <email@hidden>
- Date: Sun, 17 Apr 2011 15:43:20 -0300
On Apr 17, 2011, at 12:57 PM, Scott Ribe wrote:
> On Apr 16, 2011, at 9:04 PM, WT wrote:
>
>> Among other things, I wanted to replace my usage of @synchronized singletons...
>
> Why? As a learning experience, experimenting with GCD, what you're doing is somewhat instructive.
That's one of the reasons.
> But your stated goal seems pointless to me. Whether you use @synchronized, explicit NSLocks, pthread locks, OS spinlocks, OS atomics, memory barriers, or inject a tiny bit of C++ (the ability to assign the result of a computation to a static) + a compiler option (ensure statics are only initialized once) is unlikely to affect anything.
That's not what I keep reading/hearing. Apple's made a big push for GCD in WWDC 2010, even on iOS devices.
>> I have a singleton that takes care of all things core data (well, all things that can be done generically). Likewise, I have a singleton for locale "utilities". All my number and date formatters are there, in one place, created once on demand and accessible everywhere else through the singleton. That's the kind of usage I have for singletons.
>
> Well, maybe it is time for a philosophical discussion. You could go through all the work of making these into true singletons and calling a method to access them for every single use, or you could initialize a handful of globals at startup and just use them.
I think that's an oversimplification of how things get used. See my reply to Kyle's last message for some examples of how/why I use singletons.
WT
_______________________________________________
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