main thread communicating with background thread and vice-versa
main thread communicating with background thread and vice-versa
- Subject: main thread communicating with background thread and vice-versa
- From: John Love <email@hidden>
- Date: Fri, 21 Nov 2008 09:24:22 -0500
From the main Thread, I call:
[NSThread detachNewThreadSelector:@selector(bgThread:) toTarget:self
withObject:nil];
- (void) bgThread:(NSConnection*)connection {
NSAutoreleasePool *pool;
pool = [[NSAutoreleasePool alloc] init];
[self doCalculation];
[self performSelectorOnMainThread:@selector(endBgCalculation:)
withObject:nil waitUntilDone:NO];
[pool release];
}
- (void) endBgCalculation:(id)obj {
// stuff
}
I believe this is fairly standard way to institute a background thread …
The problem centers on letting the background Thread look at a parm
set in the main Thread and break out of the background Thread when the
background Thread sees a certain value.
Specifically, my –doCalculation is just one great time-consuming for-
loop that looks at mainThreadParm and breaks depending on the value
of mainThreadParm.
I change mainThreadParm in the main Thread and I expect the background
Thread to break when the background Thread sees a certain value of
mainThreadParm.
The background thread sees the initial value of mainThreadParm, but
does not break when the main Thread changes it.
This sounds so basic and fundamental that I really feel lacking on
this subject.
John Love
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden