Re: Singletons and Threads
Re: Singletons and Threads
- Subject: Re: Singletons and Threads
- From: Mike Abdullah <email@hidden>
- Date: Fri, 14 Sep 2007 12:30:53 +0100
um, well it rather depends how you've written your singleton code
surely? Unless you've explicitly written the code to have different
instances per-thread, it should always be the same.
However, the thing to be wary of is that 2 threads both call
+sharedInstance for the first time, and at about the same time, you
could end up creating 2 instances, one of which would then be leaked.
So make sure your code has a proper lock around it.
Mike.
On 14 Sep 2007, at 11:45, Randall Wood 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.
_______________________________________________
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:
40mikeabdullah.net
This email sent to 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