Maintaining *one* singleton over >1 thread
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.