Threading Question
Threading Question
- Subject: Threading Question
- From: Jonah Horowitz <email@hidden>
- Date: Mon, 24 Oct 2005 18:56:44 -0700 (PDT)
I've been going over the documentation on threads under cocoa. I've
looked at both the SimpleThreads and TrivialThreads sample projects.
I have one main "controller" thread that manages everything and it
spawns two worker threads using the "+connectWithPorts" function in the
sample code.
I've pasted the snippet here:
+ (void)connectWithPorts:(NSArray *)portArray
{
NSLog(@"ConnectWithPorts Called thread id = %d",[NSThread
currentThread]);
NSAutoreleasePool *pool;
Getter *getterObject;
NSConnection *connectionToStufferController;
pool = [[NSAutoreleasePool alloc] init];
connectionToStufferController = [NSConnection
connectionWithReceivePort:[portArray objectAtIndex:3]
sendPort:[portArray objectAtIndex:2]];
getterObject = [[self alloc] init];
[[portArray objectAtIndex:6] unlock];
[ ((StufferController *)[connectionToStufferController rootProxy])
setGetterServer:getterObject];
[getterObject release];
[[NSRunLoop currentRunLoop] run];
[pool release];
return;
}
I've had no problems whatsoever calling functions in my worker threads,
but I can't figure out how to communicate from my worker threads back
to the controller thread when the controller didn't initiate the
coversation.
I'm using NSURLDownload to retrieve a file and when it completes the
download it calls a downloadDidFinish delegate in my worker thread.
How can my worker thread call my controller thread to let it know that
the download is complete.
I've tried moving the NSConnection up out of the connectWithPorts and
into the class implementation, but that seems to crash the program when
connectWithPorts is called.
I'm totally lost and I've been banging at this for hours. Any help
would be greatly appreciated.
Thanks,
Jonah Horowitz
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden