Re: Singletons and Threads
Re: Singletons and Threads
- Subject: Re: Singletons and Threads
- From: "Clark Cox" <email@hidden>
- Date: Fri, 14 Sep 2007 07:32:08 -0700
On 9/14/07, Randall Wood <email@hidden> wrote:
> If I have a class that is a singleton, and create the first instance in a
> thread using a standard [sharedInstance] method, will calling
> [sharedInstance] in another thread use that single instance, or will each
> thread get its own instance of the class?
> Searching about, I can't find an explicit answer to this question.
That all depends on how you've written your class. You could write it
to function either way. Odds are, if you've written it the most
straightforward way (i.e. storing a pointer to the singleton in a
static variable), all threads will share the same instance.
As a side note, be sure that you've adequately protected your
sharedInstance method from threading problems. It would be best if you
posted your code, without that, any answer you get will just be
conjecture.
--
Clark S. Cox III
email@hidden
_______________________________________________
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