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: Scott Ribe <email@hidden>
- Date: Sun, 17 Apr 2011 09:57:55 -0600
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. 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.
> 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.
--
Scott Ribe
email@hidden
http://www.elevated-dev.com/
(303) 722-0567 voice
_______________________________________________
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