• 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: Singleton instances and multithreading
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Singleton instances and multithreading


  • Subject: Re: Singleton instances and multithreading
  • From: Jean-François Veillette <email@hidden>
  • Date: Thu, 12 Jul 2001 20:10:53 -0400

This exact code will work in single-threaded mode, just leave mylock to null.
Once you know you are going multi-thread, you could post a notification, initialize mylock to an instance of NSLock, and you are done. I'm not sure, but IIRC there is already a notification posted for that purpose.
Once you know you are done with multi-thread, you may clear mylock and set it to null.
A message to null is a no-op.

- jfv

I think you could put some stuff in there to check the multithreaded-ness of the program and skip the locking if it's single threaded.

+sharedInstance
{
[mylock lock];
do stuff to check/create singleton
[mylock unlock];
return singleton instance
}


References: 
 >Re: Singleton instances and multithreading (From: Mike Shields <email@hidden>)

  • Prev by Date: wrapping text in cells of an NSTableView
  • Next by Date: alloc, dealloc, retain, release, autorelease etc.
  • Previous by thread: Re: Singleton instances and multithreading
  • Next by thread: Re: Singleton instances and multithreading
  • Index(es):
    • Date
    • Thread