Re: Multiprocessor Support
Re: Multiprocessor Support
- Subject: Re: Multiprocessor Support
- From: Nick Zitzmann <email@hidden>
- Date: Tue, 12 Aug 2003 19:23:44 -0700
On Tuesday, August 12, 2003, at 11:49 AM, Lance Pysher wrote:
Several of my objects would generate several threads during the init
process. How do people make the thread wait until the tasksare done.
Well, you can do this with NSConditionLock... Try something like this:
(warning - written in Mail, untested, use at your own risk, etc.)
enum
{
threadNotDone,
threadDone
};
- (void)init
{
// do your usual init stuff, then...
someLock = [[NSConditionLock alloc]
initWithCondition:threadNotDone];
[NSThread detachNewThreadSelector:@selector(someMethod:)
toTarget:self withObject:blah];
[someLock lockWhenCondition:threadDone]; // freeze here until
someMethod: is done
[someLock unlock];
// etc...
}
- (void)someMethod:(id)blah
{
// do stuff...
[someLock lock];
[someLock unlockWithCondition:threadDone]; // get the main thread
moving again
}
Nick Zitzmann
AIM/iChat: dragonsdontsleep
Check out my software page:
http://seiryu.home.comcast.net/
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my
telephone." - Bjarne Stroustrup
_______________________________________________
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.