• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Singletons and Threads
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Singletons and Threads (From: "Randall Wood" <email@hidden>)

  • Prev by Date: Singletons and Threads
  • Next by Date: Determine pressed keys while dragging FROM OTHER application
  • Previous by thread: Singletons and Threads
  • Next by thread: Re: Singletons and Threads
  • Index(es):
    • Date
    • Thread