• 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
Maintaining *one* singleton over >1 thread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Maintaining *one* singleton over >1 thread


  • Subject: Maintaining *one* singleton over >1 thread
  • From: sinclair44 <email@hidden>
  • Date: Mon, 17 Mar 2003 20:34:32 -0500

Hello-

I'm writing a multithreaded app with a singleton that must be allocated
*exactly once*. I was doing it (when single-threaded) with +sharedInstance
and a static variable. However, when the second thread calls
+sharedInstance, a new instance is allocated (which didn't happen before)!

Is there an easy way to get a single instance of this singleton over the
entire app?

(BTW, I'm aware of multithreading issues and the locks I need to implement.)

Thanks,
sinclair44.
--

-- sinclair44

[self becomeWorldDictator];

- (void)becomeWorldDictator
{
[self coverLegalButt];

[[GeorgeBush principalClass] assassinate:[world currentLeaders]];
[[BinLaden principalClass] terrorize:[world citizens]];
[world setCurrentLeaders:[NSArray arrayWithObject:self]];
}

- (void)coverLegalButt
{
/* The above does not reflect any plans, expressed or implied, real or
imaginative, to kill or assassinate anyone, or to harm anyone in any shape,
way or form. Any relation to actual events is purely coincidental. */
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Maintaining *one* singleton over >1 thread
      • From: Jeff Disher <email@hidden>
  • Prev by Date: Determining cumulative size of an object at runtime
  • Next by Date: Re: web services?
  • Previous by thread: Re: compiler bug?
  • Next by thread: Re: Maintaining *one* singleton over >1 thread
  • Index(es):
    • Date
    • Thread