Re: Techniques for thread communication
Re: Techniques for thread communication
- Subject: Re: Techniques for thread communication
- From: Eric Scharff <email@hidden>
- Date: Mon, 8 Sep 2003 10:56:55 -0700 (PDT)
Using NSConnection really strikes me as overkill for threads.
Don't threads share the same address space, meaning that they
can easily share objects with each other?
Perhaps I should describe my thread example in more detail. I
have a worker thread that continuously searches an input space
using standard techniques like simulated annealing, genetic
algorithms, etc. The worker thread has a concept of the "best
found so far" which it stores in an instance varable.
The big deal is that the I don't want to pass the search result
around using NSCoding. It can potentially be very large, and it
is wasteful to encode and decode it.
So, my options are
1. Set up an NSTimer on the main thread, that every N seconds
queries the worker thread for the best result so far, and
displays it. Since there is always a "best so far", this method
is always meaningful.
2. A preferred mechanism is to have the worker notify the main
thread when it finds something N percent better than the last
match.
In any of the notificaiton mechanisms, can I avoid sending the
object over the port using NSCoding and simply share the object?
This would seem to work for notificaiton centers, connections,
etc.
I imagine something like this:
@implementation WorkerThread
-(void)whileRunning {
// ...
[controller performSelectorOnMainThread: @(foundMatch)]
// or something equivalent
}
-(Result *)result { return result; }
@implementation MyController
-(void)foundMatch {
[resultToShow release];
resultToShow = [[myWorker result] retain];
[myView setNeedsDisplay: YES];
}
Will this work? Is it a horrible idea?
-Eric
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
_______________________________________________
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.