Producer / Consumer
Producer / Consumer
- Subject: Producer / Consumer
- From: Marc <email@hidden>
- Date: Wed, 5 Nov 2003 11:38:34 -0500
I have a long routine (call it generate) that is activated from a UI
button which spawns a separate thread so the UI does not lock up by
calling this selector:
- (void)doGenerate:(id)anObject {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[NSThread setThreadPriority:1.0];
[self generate];
[pool release];
NSLog(@"Generate Thread Terminating.");
}
-(void) generate also calls itself and when the generate calls return
they unwind and eventually complete this thread.
Essentially, generate is using one processor more or less completely
leaving the other processor to run the UI and any other system or user
processes on the machine. The program is running to solve a specific
problem and as such I don't need it to be a "good citizen" regarding
other programs - I want it to uses as much CPU as possible, i.e.
utilize the second CPU as well.
Within generate there are say 100 conditions that need to be evaluated
to find the best one before calling generate again recursively.
Currently I do this in a loop, but wonder what is the best way to do
this to utilize the second processor too as the 100 evaluations are not
dependent upon one another. The evaluations may take some time (say
1-5 minutes each currently in the loop) so would it be better to just
spawn 100 threads to evaluate each condition and then unblock the
generate threat when they all complete? Or just set up 2 more
"evaluation" threads which would be "consumers" of the conditions the
"producer" generate thread would provide? I suppose a NSConditionLock
would be the way to go on the generate thread to know that the
evaluation threads are complete in either solution so I don't have to
poll.
_______________________________________________
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.