• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Threading Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Threading Question


  • Subject: Re: Threading Question
  • From: Dustin Voss <email@hidden>
  • Date: Tue, 25 Oct 2005 18:30:29 -0700

InterThreadMessaging (http://www.cocoadev.com/?InterThreadMessaging) allows arbitrary threads to call selectors and send notifications to other threads.

It works well.


On 24 Oct 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
References: 
 >Threading Question (From: Jonah Horowitz <email@hidden>)

  • Prev by Date: Re: NSMailDelivery
  • Next by Date: beeps in response to key presses
  • Previous by thread: Re: Threading Question
  • Next by thread: Re: Threading Question
  • Index(es):
    • Date
    • Thread