Re: Techniques for thread communication
Re: Techniques for thread communication
- Subject: Re: Techniques for thread communication
- From: Drew McCormack <email@hidden>
- Date: Mon, 8 Sep 2003 20:27:03 +0200
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?
Seems fine to me. Only thing to be careful about is not to cause
problems when you access [myWorker result]. Remember, the
performSelectorOnMainThread: is asynchronous, meaning it doesn't wait
for foundMatch to finish before continuing. You may need an NSLock in
the 'result' method to control access to it.
This is very close to the consumer/producer pattern. You can also solve
this with NSConditionLock. It can block one thread until some condition
is met, eg. a new result becomes available. Read the docs if you want
to know more, and check out cocoadev.com.
http://www.cocoadev.com/index.pl?ProducersAndConsumerModel
Drew
----------------------------------
Dr. Drew McCormack
Trade Strategist (www.trade-strategist.com)
Stock Market strategy design platform for Mac OS X.
_______________________________________________
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.