Re: NSOperationQueue
Re: NSOperationQueue
- Subject: Re: NSOperationQueue
- From: Quincey Morris <email@hidden>
- Date: Fri, 19 Sep 2008 16:07:37 -0700
On Sep 19, 2008, at 08:15, John Love wrote:
9) Its -startCalculation looks like:
- (void) startCalculation {
int row;
// itsCalcStatus = kNoError; // set by -init
for (row=1; row < 10000; row++) {
if (itsCalcStatus == kSpreadsheetStopped) break;
if (itsCalcStatus != kNoError) break;
itsCalcStatus = kSpreadsheetCalculating;
[self startOperation]; // start new thread
// if running in background, this will have no effect:
[itsQueue waitUntilAllOperationsAreFinished];
}
This method is being executed on the main thread (unless I missed
something). '[self startOperation]' causes (eventually) a new thread
to be created, executing the 'calculateWorksheetRow' method. But
'startCalculation' continues in the main thread and reaches '[itsQueue
waitUntilAllOperationsAreFinished]'. At that point, it blocks waiting
for the background operations to finish. So your main thread has
stopped dead, and of course your application becomes unresponsive,
until the background threads all complete.
I think the simplest way to achieve what you want is to remove
'[itsQueue waitUntilAllOperationsAreFinished]' completely, move the
rest of 'startCalculation' to a new method, and create an extra
operation that runs this new method. Use [NSOperation addDependency:]
to make this extra operation dependent on all the calculation
operations, then add the extra operation to your queue.
Or something like that.
_______________________________________________
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