Re: Multithreaded App - Help
Re: Multithreaded App - Help
- Subject: Re: Multithreaded App - Help
- From: Lloyd Sargent <email@hidden>
- Date: Sun, 5 Aug 2001 14:34:30 -0500
Hi
I'm new to Objective-C/Cocoa programming on Mac OS X. I want to create a
multithreaded app. After reading OS X's Developer documentation on
NSThread, I'm still confused about this. I understand that I need to
call detachNewThreadSelector method, but what do I specify for the
selector, toTarget and withObject arguments?
I think I pretty much understand the other methods, i.e. exit, etc.
Thanks!
Yuhui
Okay, threads actually are pretty easy. For example, here is an excerpt
from some of my current code (which continuously polls hardware in the
background). This will PROBABLY get you going. If it doesn't, e-mail me
off the list and I will go into more detail.
Cheers,
Lloyd
-----
Canna Software Development
"No animals were harmed in the creation of this email, however some
routers suffered painful bumps and bruises."
//---- controller code
- (void) awakeFromNib
{
Hardware *hardware;
hardware = [[Hardware alloc] init]; // this is where I create my
hardware object
}
//----- this is my code in the hardware object
- init
{
self = [super init];
[NSThread detachNewThreadSelector:@selector(runLoop)
toTarget:self
withObject:nil];
return self;
}
- (void) dealloc
{
[super dealloc];
}
- (void) runLoop
{
NSAutoreleasePool *localPool;
while (YES)
{
localPool = [[NSAutoreleasePool alloc] init];
// interesting stuff happens in here
[localPool release];
}
}