Re: Threading Question
Re: Threading Question
- Subject: Re: Threading Question
- From: Jonah Horowitz <email@hidden>
- Date: Mon, 24 Oct 2005 19:40:12 -0700 (PDT)
That seems reasonable, my problem is that I'm not sure how to call
performSelectorOnMainThread... I need a pointer to the main thread,
which I don't have. I can have the main thread call a function after
detachNewThread... which sets the value of a thread variable, like so:
- (void)setGlobalController:(MainController *)controller
{
globalController = controller;
}
globalController being defined in my worker.h as
MainController* globalController;
but this just doesn't seem like it's the right way to do it.
Jonah
--- Ryan Britton <email@hidden> wrote:
> Try performselectorOnMainThread:withObject:waitUntilDone:
>
> http://developer.apple.com/documentation/Cocoa/Reference/Foundation/
>
ObjC_classic/Classes/NSObject.html#//apple_ref/doc/uid/20000050-CJBEHAEF
>
> Just have the delegate method call a finishing method using that.
>
> On Oct 24, 2005, at 6:56 PM, Jonah Horowitz wrote:
>
> > 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
> >
>
>
_______________________________________________
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